highlight a row when total is in column A

  • Thread starter Thread starter Rock
  • Start date Start date
R

Rock

Hello all, I was searching for some excel vba code that would search
column A and if the word Total is found then that row is highlighted
with a color, from column A to Column G..

Any suggested vba code? Thanks...
 
Do you specifically want to use code ?

I'd suggest Conditional Formatting as an easier option.

Regards

Trevor
 
Rock,

Try this:


Sub test()
Dim iEnd As Long, i As Range, iRng As Range

iEnd = Cells(Rows.Count, 1).End(xlUp).Row
Set iRng = Range(Cells(1, 1), Cells(iEnd, 1))

For Each i In iRng
If i.Value = "Total" Then
With i.Resize(, 6).Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
End If
Next i

End Sub
 
Here is some code using Find/FindNext

Sub ColourTotals()
Dim rngFound As Range
Dim strFirstAddress As String

Set rngFound = Columns("A").Find(What:="total", _
LookAt:=xlPart, _
LookIn:=xlValues, _
MatchCase:=False)
If Not rngFound Is Nothing Then
strFirstAddress = rngFound.Address
Do
rngFound.Resize(, 7).Interior.ColorIndex = 40
Set rngFound = Columns("A").FindNext(rngFound)
Loop Until rngFound.Address = strFirstAddress
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top