Consulting

Results 1 to 3 of 3

Thread: Conditional formatting for entire row for text based values using VBA code

  1. #1

    Conditional formatting for entire row for text based values using VBA code

    Hi,
    I would like to highlight the entire row in an MS Excel2003 using conditional formatting based on a particular cell value. A similar thing has been solved here. ( I can't give the hyperlink here as I am a newbie but the code is given at the end of this email message. This is solved by DRJ. KB ID is 90)
    All I require is a tweak that will highlight the entire row instead of just the cell which it is doing currently.
    Also can anyone let me know a proper primer of VBA that helps a newbie understand VBA code. Ideally I should have been able to decode the VBA code and tweak it to my requirement, instead of wasting someone's precious time.
    Thanking you in advance.
    Warm Regards,
    Kallol

    Code:

    Option Compare Text 'A=a, B=b, ... Z=zOption Explicit Private Sub Worksheet_Change(ByVal Target As Range) Dim Cell As Range Dim Rng1 As Range On Error Resume Next Set Rng1 = ActiveSheet.Cells.SpecialCells(xlCellTypeFormulas, 1) On Error Goto 0 If Rng1 Is Nothing Then Set Rng1 = Range(Target.Address) Else Set Rng1 = Union(Range(Target.Address), Rng1) End If For Each Cell In Rng1 Select Case Cell.Value Case vbNullString Cell.Interior.ColorIndex = xlNone Cell.Font.Bold = False Case "Tom", "Joe", "Paul" Cell.Interior.ColorIndex = 3 Cell.Font.Bold = True Case "Smith", "Jones" Cell.Interior.ColorIndex = 4 Cell.Font.Bold = True Case 1, 3, 7, 9 Cell.Interior.ColorIndex = 5 Cell.Font.Bold = True Case 10 To 25 Cell.Interior.ColorIndex = 6 Cell.Font.Bold = True Case 26 To 99 Cell.Interior.ColorIndex = 7 Cell.Font.Bold = True Case Else Cell.Interior.ColorIndex = xlNone Cell.Font.Bold = False End Select Next End Sub

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    try instead of the likes of:
    [vba]Cell.Interior.ColorIndex = 3
    Cell.Font.Bold = True [/vba]use:
    [vba]Cell.Entirerow.Interior.ColorIndex = 3
    Cell.Entirerow.Font.Bold = True [/vba]
    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.

  3. #3

    Many Thanks

    Hi p45cal,

    That helped.

    Thanks so much.

    Warm Regards,
    Kallol

Posting Permissions

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