Consulting

Results 1 to 6 of 6

Thread: Highlight Offset Consecutive Column Cells

  1. #1
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location

    Highlight Offset Consecutive Column Cells

    good friday,

    I am trying to highlight my cells.

    if Column A contains the word "hello" color cells B,C,D,E


     Private Sub Highlight_Range()
        
        For Each oCell In ThisWorkbook.Worksheets("test").Range("A1:A100").Cells
        
        ' How may i color cells , C,D,E,F?
        
        If oCell = "hello" Then oCell.Offset(, 1).Interior.ColorIndex = 3
        
        Next
    
        End Sub

    Example

    A5 contains "hello"

    now
    A5 ,B5,C5,D5,E5 should be red

    I only managed to color B
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  2. #2
    VBAX Expert
    Joined
    May 2016
    Posts
    604
    Location
    You can do this with conditional formating, select range A1 to E1 then select conditional formatting , then select "use a formula to determine which cells to format, enter the following in the box for the formula: =$A1="Hello", then select the format that you want.
    Then copy the format down the rest of the worksheet

  3. #3
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    hello there,

    thank you for tip

    oh yes i forgot about that.

    now what about all the other rows in the column

    Do i extend my range?
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  4. #4
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    I have extended the range and it seems to work so far.

    let me do some more testing
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  5. #5
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
     If oCell = "hello" Then oCell.Resize(, 6).Interior.ColorIndex = 3 'colours A:F
            If oCell = "hello" Then oCell.Offset(, 1).Resize(, 4).Interior.ColorIndex = 3 'colours B:E
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  6. #6
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    thank you p45cal,

    The resize property is one of me least favourite things,

    because i always get muddled up with it no matter how many times i try to use it elegantly in my code.

    I always find it hard to see it visually.

    Hence having resize amnesia

    but yes this does the trick,

    thank you for the line of code

    and great weekend all!
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


Posting Permissions

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