Search for Values part2

S

smandula

Somehow my question got changed?

I like to thank the Big Guns (developers) for their answer but May I
offer a more humble solution. I doesn't work properly, so if someone
could look at it I would appreciate it.
'--------------------------------------------------------------------
Sub Macro1Find()

'Clear the current range
Range("B1:F6").Select
Selection.Interior.ColorIndex = xlNone

For i = 1 To 10 ' Look at values in A1 to A10
Lookupvalue = Cells(i, 1).Value

With Range("B2:F6")
Set C = .Find(Lookupvalue, LookIn:=xlValues)
If Not C Is Nothing Then
'(if match then highlight the cell in range}
Range(C.Address).Select
With Selection.Interior
.ColorIndex = 39
.Pattern = xlSolid
End With
End If
End With
Next

End Sub

'------------------------------------------------------------------------
 
N

Nigel

It is better not to start a new thread, however the following code works for
me. Slight modification to your version.

Sub Macro1Find()
Dim lookupvalue As String
Dim c As Range
Dim i As Integer

'Clear the current range
Range("B1:F6").Interior.ColorIndex = xlNone

For i = 1 To 10 ' Look at values in A1 to A10
lookupvalue = Trim(Cells(i, 1).Value)

With Range("B2:F6")
Set c = .Find(lookupvalue, LookIn:=xlValues)
If Not c Is Nothing Then
'(if match then highlight the cell in range}
With Range(c.Address).Interior
.ColorIndex = 39
.Pattern = xlSolid
End With
End If
End With
Next

End Sub
 
S

smandula

Thanks Nigel,

I don't know what happen! Your solution works great.

When I tried my original solution; it also worked.

Thanks, your method is more elegant.
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

Top