View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Basilisk96 Basilisk96 is offline
external usenet poster
 
Posts: 37
Default I want to highlight multiple cells using VB

That will fail when a match is not found because the string will be
empty, and will also fail when the string grows too long... The Union
approach is more robust.

-Basilisk96


"Nigel" wrote:
Sub mySelector()
Dim myRange As Range, myCell As Range
Dim mySelection As String

Set myRange = Range("A1:A100")
mySelection = ""

For Each myCell In myRange
If ActiveCell.Value = myCell.Value Then
If Len(mySelection) < 0 Then
mySelection = mySelection & ","
End If
mySelection = mySelection & myCell.Address
End If
Next
Range(mySelection).Select
End Sub

--

Regards,
Nigel