Hi,
I am trying to run a macro that will
1. open a search box
2. when a number is entered the cell is highlighted and the background colour is changed
3. Then once that cell has been changed a new search box is opened and we start again with a new number
4. the macro ends when i click cancel on the dialog box.
I have the following code, and it does the first part well, i just can get it to loop
Any idea?
<CODE>
Sub FindAndColour()
Dim c as range
Dim Findstr As String
Findstr = InputBox("Enter search string") ' Enter your search string
With Worksheets(1).Range("a1:D500") ' Change to reflect your search range
Set c = .Find(Findstr, LookIn:=xlValues,Lookat:=XlWhole)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.EntireRow.Interior.ColorIndex = 4 ' Set row to green
Set c = .FindNext(c) ' Look for next occurence of search string
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
</CODE>
I am trying to run a macro that will
1. open a search box
2. when a number is entered the cell is highlighted and the background colour is changed
3. Then once that cell has been changed a new search box is opened and we start again with a new number
4. the macro ends when i click cancel on the dialog box.
I have the following code, and it does the first part well, i just can get it to loop
Any idea?
<CODE>
Sub FindAndColour()
Dim c as range
Dim Findstr As String
Findstr = InputBox("Enter search string") ' Enter your search string
With Worksheets(1).Range("a1:D500") ' Change to reflect your search range
Set c = .Find(Findstr, LookIn:=xlValues,Lookat:=XlWhole)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.EntireRow.Interior.ColorIndex = 4 ' Set row to green
Set c = .FindNext(c) ' Look for next occurence of search string
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
</CODE>