VBA Lookup Value Copy, Paste Values between two workbooks

SDave

Board Regular
Joined
Aug 12, 2008
Messages
147
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:

RolfJ

Banned
Joined
Jul 29, 2009
Messages
333
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?
 

SDave

Board Regular
Joined
Aug 12, 2008
Messages
147
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.
 

John Davis

Well-known Member
Joined
Sep 11, 2007
Messages
3,457
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.
 

SDave

Board Regular
Joined
Aug 12, 2008
Messages
147
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
 

RolfJ

Banned
Joined
Jul 29, 2009
Messages
333
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
 

SDave

Board Regular
Joined
Aug 12, 2008
Messages
147
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.
 

SDave

Board Regular
Joined
Aug 12, 2008
Messages
147
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.
 

Forum statistics

Threads
1,081,730
Messages
5,360,934
Members
400,602
Latest member
newaqua

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top