ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Search for Values part2 (https://www.excelbanter.com/excel-programming/421768-search-values-part2.html)

smandula

Search for Values part2
 
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

'------------------------------------------------------------------------

Nigel[_2_]

Search for Values part2
 
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

--

Regards,
Nigel




"smandula" wrote in message
...
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

'------------------------------------------------------------------------



smandula

Search for Values part2
 
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


All times are GMT +1. The time now is 07:51 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com