View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
HeatherO HeatherO is offline
external usenet poster
 
Posts: 41
Default vlookup in a msword macro returning an error

I am doing a vlookup in a word macro and I keep getting an error as the value
returned which is error 2042. I am unsure what exactly that error is and I
capture it using the iserror method but what I would really like is the
actual value from the spreadsheet I am doing the lookup on. A sample of my
code is below:

AppXL.workbooks.Open ("C:\Model Pilot\Listing" & dlrrep & ".xls")
AppXL.workbooks.Open ("C:\Model Pilot\Model Grid_test.xls")
AppXL.workbooks.Open ("C:\Model Pilot\Names.xls")


workbooks("Listing" & dlrrep & ".xls").worksheets("Sheet1").Activate
With Activesheet
'get the last row of data for the ranges.
lislrow = AppXL.Cells(Rows.Count, "A").End(xlUp).Row
For counter = 2 To lislrow
lokval = AppXL.Cells(counter, 15).Value
'row Z - col L of model grid
res = AppXL.vlookup(lokval, workbooks("Model
Grid_test.xls").Sheets("Sheet1").Range("A2:M55"), 12, False)
If IsError(res) Then
AppXL.Cells(counter, 26).Value = ""
Else:
xlApp.Cells(counter, 26).Value = res
End If
next counter

The value it is supposed to return is "scs". Any help is appreciated even
if I knew what the error 2042 is I could figure out what might be my problem.
If I do it from excel in the spreadsheet it doesn't have any errors so I'm a
little stumped.
TIA
Heather