Using Find when you have more than one occurrence

  • Thread starter Thread starter a
  • Start date Start date
A

a

Hello,

I am trying to use Find to find each occurrence of "Total" in a dynamic
range and then to change the font to bold on each of the columns in the
Total row. I don't know how to get this to work more than once. The
following code will work for the first occurrence - but I can't seem to
figure out how to get it to do the same with any other occurrence.

Can anybody help me with this?

As always, any help would be greatly appreciated.

Best Regards,
Anita


Sub ThisWorks()
'this works but it needs a way to search more than once


Dim i As Integer

Columns(3).Select
Selection.Find(What:="Total", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
i = 1
Do Until i = 19
ActiveCell.Offset(rowOffset:=0, columnOffset:=1).Activate
ActiveCell.Font.Bold = True
i = i + 1
Loop
End Sub
 
Try this one

Sub test()
Dim FoundCell As Range
Dim firstAddress As String
With Range("C:C")
Set FoundCell = .Find("Total", After:=Range("C" _
& Rows.Count), LookAt:=xlPart)
If Not FoundCell Is Nothing Then
firstAddress = FoundCell.Address
Do
FoundCell.Offset(0, 1).Resize(1, 19).Font.Bold = True
Set FoundCell = .FindNext(FoundCell)
Loop While Not FoundCell Is Nothing And FoundCell.Address <> firstAddress
End If
End With
End Sub
 
Thank you Ron de Bruin!! This works exactly the way I wanted. Also -
thanks for adding the resize code. I was too lazy to figure out how to
incorporate it and it is so much nicer than what I was doing.

Thanks again!
 

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