I need help with a macros to compare column "O" in two sheets:
Find Stock Symbol sheet
and Stock & Symbol Data sheet.
Here's a sample file:
Company Name3.xlsm
The code I made below works, but it only matches the first instance of a match and doesn't consider any other matches. I appreciate any help you can give.
Another more experienced member had mentioned that it's possible to make a code that finds all matches and puts them into a userform which pops up and the user can click on which is the best match.
For example:
Which company is the best match?
[] Coca Cola
[] CocaCola
[] Coca-Cola
etc.
'Macro looks at each cell in Column O from "Find Stock Symbol" sheet and compares _
'to all data cells in Column O of "Stock & Symbol Data" sheet
Sub FindStocksContainingSearch()
Dim LastRowBofF As Long
LastRowBofF = Sheets("Find Stock Symbols").Range("B" & Rows.Count).End(xlUp).Row
Dim LastRowBofS As Long
LastRowBofS = Sheets("Stock & Symbol Data").Range("B" & Rows.Count).End(xlUp).Row
Dim FindResult As Range
For x = 5 To LastRowBofF
'For y = 5 To LastRowBofS
'comp = Worksheets("Find Stock Symbols").Range("B" & x).Value
Dim FindResultO As Range
'If there is a company in Column "B"
If Sheets("Find Stock Symbols").Range("B" & x).Value <> "" Then
'If there is a blank in Find Stock Symbols sheet column C, then
If Sheets("Find Stock Symbols").Range("C" & x).Value = "" Then
Set FindResultO = Sheets("Stock & Symbol Data").Range("O5:O" & LastRowBofS).Find(What:=Worksheets("Find Stock Symbols").Range("O" & x).Value, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False)
End If
End If
If Not FindResultO Is Nothing And Sheets("Find Stock Symbols").Range("B" & x).Value <> "" Then
Dim iReply1 As Integer
iReply1 = MsgBox(Prompt:="Are these the same companies: " & Worksheets("Find Stock Symbols").Cells(x, 2).Value & " = " & FindResultO.Offset(0, -13).Value & " ? ", _
Buttons:=vbYesNo, Title:="Same Companies?")
If iReply1 = vbYes Then
Worksheets("Find Stock Symbols").Range("C" & x).Value = FindResultO.Offset(0, -14).Value
End If
If iReply1 = vbNo Then
Worksheets("Find Stock Symbols").Range("C" & x).Value = "NOT FOUND: Please Find the Symbol Manually"
End If
End If
Next x
End Sub
Bookmarks