Highlighting Found Cells

  • Thread starter Thread starter 1clncc
  • Start date Start date
1

1clncc

In Excel, with Ctrl and mouse, I can click multiple cells. Those
cells would then be temporarily, until next mouse click, stay in a
Blue Hightlited state.

How can I achieve that with the below FIND rountine for those found
cells

************************************************************
With Range("Post_Code2")
Set c = .find(NNN, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Interior.Pattern = xlPatternGray50
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
********************************************************************
 
I'm tired, so this might be a bit cumbersome, but it seems to work:

Sub SelectAllFound()
Dim c As Range, firstaddress As String, newc As Range
With Range("Post_Code2")
Set c = .Find("NNN", LookIn:=xlValues)
If Not c Is Nothing Then
Set newc = c
firstaddress = c.Address
Do
Set c = .FindNext(c)
Set newc = Union(newc, .FindNext(c))
Loop While Not .FindNext(c) Is Nothing And c.Address <>
firstaddress
End If
End With
newc.Select
End Sub

I wasn't sure what NNN was supposed to be so I changed it to the string
"NNN".
_______________________________________________________________________
 

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