Copy cell to other workbook, based on value.

Ilfalco87

New Member
Joined
Dec 19, 2016
Messages
7
Hello. I have a question regarding vba.

I want to copy cell values 09, 011 and O13 of workbook A, to column D, J and K of workbook B. First I need to find cell value O7 (workbook A) in column A of workbook B. The copied data needs to fill the blank cells of workbook B.

For example, number 11023 can be found in cell number A20. So D20, J20 and K20 need the new data.

I managed to copy paste values to workbook B, but I'm stuck at finding the correct row.

Thank you!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Your request doesn't match your example, so, try my macro for what I understood and if it doesn't meet your needs you can use it as a starting point and edit/change it as you like. The is to be pasted in a vbe module of Workbook A and when run Workbook B must already opened.
VBA Code:
Option Explicit
Sub Copy_Find_Paste()
    Dim wb1    As Workbook
    Dim wb2    As Workbook
    Dim sh1    As Worksheet
    Dim sh2    As Worksheet
    Dim fndColA As Range
    Application.ScreenUpdating = False
    Set wb1 = ThisWorkbook
    Set wb2 = Workbooks("Workbook B.xlsx")        '<- change file name as needed
    Set sh1 = wb1.Sheets("Sheet1")                '<- adjust sheet name Workbook A as needed
    Set sh2 = wb2.Sheets("Sheet1")                '<- adjust sheet name Workbook B as needed
    Set fndColA = sh2.Range("A:A").Find(What:=sh1.Cells(7, "O"), LookIn:=xlValues, LookAt:=xlWhole) 'search O7 of Wb1 in Wb2 column A
    If Not fndColA Is Nothing Then                'if found ...
        sh1.Cells(9, "O").Copy sh2.Cells(fndColA.Row, "D")
        sh1.Cells(11, "O").Copy sh2.Cells(fndColA.Row, "J")
        sh1.Cells(13, "O").Copy sh2.Cells(fndColA.Row, "K")
    Else
        MsgBox Cells(7, "O") & " not found in workbook " & wb2.Name
        Exit Sub
    End If
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    MsgBox "Done!"
End Sub
 
Upvote 0
Glad having been of some help(y).
Would be interesting to know which tweaks came up just to realize what I didn't guess.
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,255
Members
449,075
Latest member
staticfluids

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