Problem Macro not searching correctly.

freerskys

New Member
Joined
Jul 24, 2014
Messages
29
Office Version
  1. 2010
Platform
  1. Windows
Hello Friends,

This Macro will loop through rows to match column A on Sheet1 with column A on sheet2. On a non-match "No Match" will be put in Sheet1 column Q. On a match Sheet2 columns A,B,C,D and E will be copied to Sheet1 columns O,P,Q,R and S. What needs fixing is, while searching for an exact match for "193 AAA" it thinks 93 AAA is a match or 34 BBB = 3 BBB is a match, but it's not.
Any info is appreciated, thanks,

Sub MatchColumns()
Dim I, total, fRow As Integer
Dim found As Range


total = Sheets(1).Range("A" & Rows.Count).End(xlUp).Row


For I = 2 To total
answer1 = Worksheets(1).Range("A" & I).Value
Set found = Sheets(2).Columns("A:A").Find(what:=answer1) 'finds a match
If found Is Nothing Then
Worksheets(1).Range("Q" & I).Value = "NO MATCH"
Else

fRow = Sheets(2).Columns("A:A").Find(what:=answer1).Row
Worksheets(1).Range("O" & I).Value = Worksheets(2).Range("A" & fRow).Value
Worksheets(1).Range("P" & I).Value = Worksheets(2).Range("B" & fRow).Value
Worksheets(1).Range("Q" & I).Value = Worksheets(2).Range("C" & fRow).Value
Worksheets(1).Range("R" & I).Value = Worksheets(2).Range("D" & fRow).Value
Worksheets(1).Range("S" & I).Value = Worksheets(2).Range("E" & fRow).Value

End If
Next I


End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Would "193 AAA" or "93 AAA" be the entire cell contents?
 
Upvote 0
Thanks for the reply, search in 6500 cells or more.
 
Last edited:
Upvote 0
You haven't answered my question.
 
Upvote 0
In that case try
Code:
Set Found = Sheets(2).Columns("A:A").Find(answer1, , , xlWhole, , , False, , False) 'finds a match
 
Upvote 0
Wow, worked like a charm.
Not only are you fast your the best.
I wish I could be good as you one day to help someone.
Thanks.
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top