Using the following code
I create a list of approved names based on a list of existing approved names, and a source list. So the source list is scanned and if an item matches something which is in the approved names list, it is added to a different column.
The problem is that based on my source data, and my approved names - i sometimes get the wrong result, I know why - I just don't know how to fix it.
Sample data - Source List
Super Brugsen Had
SuperBest HJo
SU
Approved Names list
Super Brugsen
SuperBest
SU
Running the loopcells on that list, will produce
SU
SuperBest
SU
istead of
Super Brugsen
SuperBest
SU
Any ideas on how i correct this behavior?
Code:
Sub LoopCells()
Sheets("RawData").Select
Sheets("RawData").Activate
LRApproved = Cells(Rows.Count, "H").End(xlUp).Row
LRsource = Cells(Rows.Count, "G").End(xlUp).Row
For Each approvedcell In Worksheets("RawData").Range("H2:H" & LRApproved).Cells 'Approved stores entered by users
For Each sourcecell In Worksheets("RawData").Range("G2:G" & LRsource).Cells 'items fround from bank statement export
If InStr(UCase(sourcecell.Value), UCase(approvedcell.Value)) <> 0 Then
sourcecell.Offset(0, 2).Value = approvedcell.Value
End If
Next sourcecell
Next approvedcell
End Sub
I create a list of approved names based on a list of existing approved names, and a source list. So the source list is scanned and if an item matches something which is in the approved names list, it is added to a different column.
The problem is that based on my source data, and my approved names - i sometimes get the wrong result, I know why - I just don't know how to fix it.
Sample data - Source List
Super Brugsen Had
SuperBest HJo
SU
Approved Names list
Super Brugsen
SuperBest
SU
Running the loopcells on that list, will produce
SU
SuperBest
SU
istead of
Super Brugsen
SuperBest
SU
Any ideas on how i correct this behavior?