Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Sep 2010
    Location
    Cheltenham, Gloucestershire, UK
    Posts
    12
    Thanks
    4
    Thanked 0 Times in 0 Posts

    VBA case fucntoin for conditional formatting to update entire row

    I have 6 conditions so need to use the lovely case function. However, I need to colour the entire row not just the relevant cell.

    Column C contains the possibility of Conditon-1, Conditon-2,Condition-3,Conditon-4, Condition-5 or Condition-6. But I need to have the whole row change colour not just cells in column C

    Code for column C currently

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim icolor As Integer
    If Not Intersect(Target, Range("C1:C700")) Is Nothing Then
    Select Case Target
    Case "Condition-1"
    icolor = 6
    Case "Condition-2"
    icolor = 12
    Case "Condition-3"
    icolor = 7
    Case "Condition-4"
    icolor = 53
    Case "Condition-5"
    icolor = 15
    Case "Condition-6"
    icolor = 22
    Case Else
    End Select
    Target.Interior.ColorIndex = icolor
    End If
    End Sub

    Thanks

    Roberta

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts
    How about:
    Target.EntireRow.Interior.ColorIndex = icolor

    Steve

  3. The Following User Says Thank You to sdckapr For This Useful Post:

    robertaw (2011-04-25)

  4. #3
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Roberta,

    If you only want to color the used part of the worksheet rows rather than out to the last column, which would make for a smaller file size use something like this:
    Code:
     
        Dim lLastCol As Long
        Dim lCurRow  As Long
       
        lLastCol = ActiveCell.SpecialCells(xlCellTypeLastCell).Column
        lCurRow = ActiveCell.Row
        Range(Cells(lCurRow, 1), Cells(lCurRow, lLastCol)).Interior.ColorIndex = 12
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  5. The Following User Says Thank You to RetiredGeek For This Useful Post:

    robertaw (2011-04-25)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •