I have the following piece of code that searches for custom searchwords in a spreadsheet and then highlights the rows.
How do I adjust it so it only selects the data present within those rows?
How do I adjust it so it only selects the data present within those rows?
VBA Code:
Dim Rng As Range, myUnion As Range, searchString As String
Dim myCell As Range, arrSrc, El
Set Rng = Selection
If TypeName(Rng) <> "Range" Then MsgBox "You must select a range...", vbCritical, "Wrong selection": Exit Sub
searchString = InputBox("Please type 'Sample' & any other searchwords seperated by a comma")
searchString = Replace(searchString, ", ", ",")
arrSrc = Split(searchString, ",")
For Each El In arrSrc
For Each myCell In Rng
If InStr(myCell.Text, El) Then
If Not myUnion Is Nothing Then
Set myUnion = Union(myUnion, myCell.End(xlToRight.Select))
Else
Set myUnion = myCell.EntireRow
End If
End If
Next
Next El
If myUnion Is Nothing Then
MsgBox "The text was not found in the selection"
Else
myUnion.Select
End If
'
End Sub