-
its still not working. I'm basically trying to search multiple values in a row & highlight them. This is the full code and only the concatenation seems to be having issue. Kindly advise!
Sub Find_Multiple_Values()
Dim Answer As VbMsgBoxResult
Answer = MsgBox("Are you sure you want to run the macro?", vbYesNo, "Run Find_Multiple_Values Macro")
If Answer = vbYes Then
Dim rngToSearch As Range
Dim wks As Worksheet
Dim rngFound As Range
Dim WhatToFind As Variant
Dim iCtr As Long
Dim DestCell As Range
Dim iLoop As Long
Dim lookupRng As Range
Dim mycell As Range
Dim yourQueryString As String
Set wks = ActiveSheet
'Data Range
Set rngToSearch = Application.InputBox("Select Data Range", "Obtain Range", Type:=8)
MsgBox "The cells selected were " & rngToSearch.Address
'Lookup Values Range
Set lookupRng = Application.InputBox("Lookup Values", "Select Lookup Values", Type:=8)
MsgBox "The cells selected were " & lookupRng.Address
'To capture Range info and concatenate
With lookupRng
For Each mycell In lookupRng.Rows(2).Cells
set yourQueryString = yourQueryString & "'" & mycell.Value & "',"
Next
yourQueryString = Left(yourQueryString, Len(yourQueryString) - 1) & ") VALUES ("
End With
WhatToFind = Array(yourQueryString)
With rngToSearch
For iCtr = LBound(WhatToFind) To UBound(WhatToFind)
Set rngFound = .Cells(.Cells.Count)
For iLoop = 1 To WorksheetFunction.CountIf(rngToSearch, WhatToFind(iCtr)) ' second loop
Set rngFound = .Cells.Find(What:=WhatToFind(iCtr), _
LookIn:=xlValues, LookAt:=xlWhole, _
After:=rngFound, _
MatchCase:=False)
If Not rngFound Is Nothing Then
rngFound.Interior.Color = RGB(255, 255, 0)
End If
Next iLoop
Next
End With
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules