VBA to find match, then copy and paste a range

ebcnt

New Member
Joined
Apr 24, 2007
Messages
3
I have what I think is a fairly simple process I need to perform, but haven't been able to find the VBA code in my searches.

I would like to create a macro that will do the following:
I have 2 workbooks (WB1 and WB2). Both workbooks will have a variable amount of entries in column A. I would like the macro to loop through column A of WB1 and search for a match for that cell value in column A of WB2. If it finds a match, it will copy cells BU:CA from the row that contains the matching value in WB2 and use it to replace those same cells in WB1. If it does not find a matching value, I would like it to leave cells BU:CA of WB1 unchanged.

Thank you so much.
 
****Sub FindAndCopy()
****Dim WS1 As Worksheet
****Dim WS2 As Worksheet
****Dim Rng1 As Range
****Dim Rng2 As Range
****Dim c As Range

****Application.ScreenUpdating = False
****Set WS1 = Workbooks("WS1.xlsx").Sheets("Sheet1")
****Set WS2 = Workbooks("WS2.xlsx").Sheets("Sheet1")
****Set Rng1 = ****WS1.Range(WS1.Range("A2"), ****WS1.Range("A" & Rows.Count).End(xlUp))
****Set Rng2 = ****WS2.Range(WS2.Range("A2"), ****WS2.Range("A" & Rows.Count).End(xlUp))
****For Each c In Rng1
********On Error Resume Next
********Rng2.Find(What:=c).Offset(, 2).Resize(, 18).Copy Destination:=c.Offset(, 2)
********Err.Clear
****Next c
****Set WS1 = Nothing
****Set WS2 = Nothing
****Set Rng1 = Nothing
****Set Rng2 = Nothing
****Application.ScreenUpdating = True
****End Sub
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I'm disinclined to continue..

1. With all those asterisks, that isn't even valid working code (& you ignored my request re using code tags) and
2. You didn't bother responding to my question 2.

Good luck with your project.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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