VBA Lookup Value Copy, Paste Values between two workbooks

SDave

Board Regular
Joined
Aug 12, 2008
Messages
152
Office Version
  1. 365
Platform
  1. MacOS
HELP!!!

I have a standard template worksheet called "Input" (the workbooks name is "Input Capture") which spans C12:U1100.

In addition I have a seperate worksheet which is based in an all entirely seperate workbook called "People Data" (the workbooks name is "Succession Planning") which again spans C12:U1100.

What I would ideally like is a macro which matches the value in column C and populates the entire row (much in the same way as a HLOOKUP, only pasting values) with the exception of columns M and Q.

Any help would be greatly appreciated.
 
Last edited:

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Please clarify what you mean by 'which matches the value in column C': matching what to what?. Also which worksheet do you want to populate?
 
Upvote 0
Hi Rolf,

The worksheet I would like to populate can be found in the Succession Planning workbook that I currently have.

What I would like is for users to populate the Input worksheet found in my Input Capture workbook.

From there on in a macro should perform a VLOOKUP, as opposed to a HLOOKUP (apologies, my mistake) and a populate columns C:U (excluding columns M and Q) in the Succession Planning workbook with values.

The value in column C in both workbooks/worksheets will be unique employee numbers.
 
Upvote 0
Hi Rolf,

The worksheet I would like to populate can be found in the Succession Planning workbook that I currently have.

What I would like is for users to populate the Input worksheet found in my Input Capture workbook.

From there on in a macro should perform a VLOOKUP, as opposed to a HLOOKUP (apologies, my mistake) and a populate columns C:U (excluding columns M and Q) in the Succession Planning workbook with values.

The value in column C in both workbooks/worksheets will be unique employee numbers.

Do you mean something like the following?

In Column D Succession Planning workbook:
=VLOOKUP(C1,'[Input Capture.xls]Input Worksheet'!$C$1:$U$whatever,2.false)

In Column E Succession Planning workbook:
=VLOOKUP(C1,'[Input Capture.xls]Input Worksheet'!$C$1:$U$whatever,3,false)

In Column F Succession Planning workbook:
=VLOOKUP(C1,'[Input Capture.xls]Input Worksheet'!$C$1:$U$whatever,4,false)


Copy down each Column.
 
Upvote 0
Hi Jon,

Something along those lines, however I would like a macro that would use the employee number located in the Input Capture worksheet, say C1 to find the row that contains the same employee number in my People Data worksheet within my Succession Planning workbook. From then on in it should copy the contents of cells D:U from my Input Capture worksheet and paste it into columns D:U in the corresponding employee number row in my People Data worksheet.

I did stumble across the following, but I can't for the life of me get it to work.

Sub CopyMacro()
On Error Resume Next
'Change address as appropriate
Workbooks.Open ("C:\My Documents\Book3.xls")
ThisWorkbook.Activate
'Change Name & Sheet as appropriate
For Each cell In Workbooks("Book3.xls").Sheets("Sheet1").Range("A:A")
If cell.Value = Range("A1").Value Then
cell.Offset(0, 7).Value = Range("B1").Value
Exit Sub
End If
Next cell
End Sub
 
Upvote 0
If I correctly understand what you are trying to do, it should suffice if you were to place the following formula in cell D12 of your 'People Data' worksheet:

Code:
=VLOOKUP($C12,[InputCapture.xls]Input!$C$12:$U$1100,COLUMN(D12)-2)

and then copy it to all cells in column D through U with the exception of columns M and Q.

Hope this helped,
Rolf
 
Upvote 0
Although it's slightly messy the following code seems to do the trick. I just need it to loop through column D and match values for the other corresponding rows.


Sub DataTransfer()
On Error Resume Next
Workbooks.Open ("P:\Group Reward\Team\Sam\Succession Planning Templates\Test\TEST - Talent Tool v2.xls")
ThisWorkbook.Activate
For Each Cell In Workbooks("TEST - Talent Tool v2.xls").Sheets("People Data").Range("D12:D1100")
If Cell.Value = Range("D12:D1100").Value Then
Cell.Offset(0, 6).Value = Range("J12:U1100").Value
Cell.Offset(0, 7).Value = Range("K12:U1100").Value
Cell.Offset(0, 8).Value = Range("L12:U1100").Value
Cell.Offset(0, 10).Value = Range("N12:U1100").Value
Cell.Offset(0, 11).Value = Range("O12:U1100").Value
Cell.Offset(0, 12).Value = Range("P12:U1100").Value
Cell.Offset(0, 14).Value = Range("R12:U1100").Value
Cell.Offset(0, 15).Value = Range("S12:U1100").Value
Cell.Offset(0, 16).Value = Range("T12:U1100").Value
Cell.Offset(0, 17).Value = Range("U12:U1100").Value
Exit Sub
MsgBox ("Data Transferred")
End If
Next
End Sub

Again any help would be appreciated.
 
Upvote 0
Ignore my last post, that doesn't seem to work in the way that I would have liked, seeing as data will undoubtedly be sorted from time to time!!

Sorry John but I'm a bit of a VBA novice. Would it just be a case of writing a lookup as I would do normally?

I assume that I would have to start of using the following:

Sub DataTransfer()
On Error Resume Next
Workbooks.Open ("P:\Group Reward\Team\Sam\Succession Planning Templates\Test\TEST - Talent Tool v2.xls")
ThisWorkbook.Activate


Thanks.
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,019
Members
448,938
Latest member
Aaliya13

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