Check if condition is true, then copy/paste data

blista99

New Member
Joined
Aug 28, 2015
Messages
10
Heyho everyone

I've got the following situation: 2 different workbooks (WKB2 with multiple sheets / WKB1 with only 1 sheet).
I need to check in a range in WKB1 if a cell value is the same as in a range in WKB1. If yes, then the macro should copy the corresponding cell.offset 1&2 to the left, into a new column in WKB2 (where the value has been found). If nothing is found, it doesn't have to do anything.

I've got the following code....everything but the "copy-part" (red) works correctly.
Code:
Dim wb1 As Workbook, wb2 As Workbook, lr As Long, c As Range, fn As Range
    Set wb1 = Workbooks("WKB1.xlsm")
    Set wb2 = Workbooks("WKB2.xlsm")
    lr = wb2.Sheets("Data").Cells(Rows.Count, "I").End(xlUp).row
        For Each c In Range("I2:I" & lr)
            Set fn = wb1.Sheets("List").Range("M:M").Find(c.Value, , xlValues, xlWhole)
                If Not gn Is Nothing Then
                    [COLOR=#ff0000]wb1.Sheets("List").Cells(c.row, Columns.Count).Cel.Offset(1, -1).Select
                    Selection.Copy
[/COLOR]                  wb2.Sheets("Data").Cells(c.row, Columns.Count).End(xlToLeft)(1, 2).PasteSpecial
                Else
                    
                End If
        Next

I can't do it with functions, cause the data is changing weekly.

Thank you very much for your help!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Nevermind. I figured it out by my self using this code-fragment:
Code:
wb1.Sheets("List").Range("M:M").Find(c.Value, , xlValues, xlWhole).Offset(0,-3).Copy
c.Offset(0,6).PasteSpecial

Cheers.
 
Upvote 0

Forum statistics

Threads
1,215,234
Messages
6,123,773
Members
449,123
Latest member
StorageQueen24

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