Parfumdecuir
New Member
- Joined
- Aug 24, 2021
- Messages
- 2
- Office Version
- 365
- 2019
- Platform
- Windows
Hello,
Below what I hope will be a very easy question to answer ?
I was able to find online a working script for my need (to search and select all cells that contain a specific text in worksheet)
I would simply like to limit it to a specific column or specific range of cells, and not the whole sheet. (Either by restrict the search range or the select range at the end)
In any case thanks for your time!
Below what I hope will be a very easy question to answer ?
I was able to find online a working script for my need (to search and select all cells that contain a specific text in worksheet)
VBA Code:
Sub test()
Dim c As Range, FoundCells As Range
Dim firstaddress As String
Application.ScreenUpdating = False
With ActiveSheet
'find first cell that contains "ABCDEF"
Set c = .Cells.Find(What:="ABCDEF", After:=.Cells(Rows.Count, 1), LookIn:=xlValues, LookAt:= _
xlPart, MatchCase:=False)
'if the search returns a cell
If Not c Is Nothing Then
'note the address of first cell found
firstaddress = c.Address
Do
'FoundCells is the variable that will refer to all of the
'cells that are returned in the search
If FoundCells Is Nothing Then
Set FoundCells = c
Else
Set FoundCells = Union(c, FoundCells)
End If
'find the next instance of "ABCDEF"
Set c = .Cells.FindNext(c)
Loop While Not c Is Nothing And firstaddress <> c.Address
'after entire sheet searched, select all found cells
FoundCells.Select
Else
'if no cells were found in search, display msg
MsgBox "No cells found."
End If
End With
Application.ScreenUpdating = True
End Sub
I would simply like to limit it to a specific column or specific range of cells, and not the whole sheet. (Either by restrict the search range or the select range at the end)
In any case thanks for your time!