Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vlookup with VBA

Status
Not open for further replies.

pbobel

Programmer
Jun 2, 2009
5
CA
Hi,

I am trying to use the vlookup function to populate a certain column with data from another spreadsheet. I am prompting the user to specify both the data files ( one which contains information and the one to populate). I keep getting an" Out of Range error" on the follwoing line:

Set rng = Workbooks("& RawFile").Sheets("Sheet1").Columns("C:K")

thanks.
Code:
 RawFile = Application.GetOpenFilename("Excel Files (*.xls), *.xls")
    ArchFile = Application.GetOpenFilename("Excel Files (*.xls), *.xls")

  Set wkb1 = Workbooks.Open(ArchFile)
With wkb1
   lRow = Range("A" & Rows.Count).End(xlUp).Row

[b]
Set rng = Workbooks("& RawFile").Sheets("Sheet1").Columns("C:K")
[/b]
For i = 2 To lRow
    Cells(i, 23) = Application.VLookup((Cells(i, 3)), rng, 19, False)
    
Next i
End With
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top