need help with vba, sum of vlookups

G

GregJG

i figured this code would work, i've broken it down for easy view

label15.Caption =
Application.WorksheetFunction.Sum(

Application.WorksheetFunction.VLookup(label12.Caption
Workbooks("1.xls").Sheets("1").Range("a3:b25"), 2, False)
+
Application.WorksheetFunction.VLookup(label13.Caption
Workbooks("2.xls").Sheets("1").Range("a3:b25"), 2, False)
+
Application.WorksheetFunction.VLookup(label14.Caption
Workbooks("2.xls").Sheets("1").Range("a1:e200"), 5, False)
)

but am getting the error " unable to get the vlookup property of th
worksheet function"

i also figure i will run into a problem if the vlookup results ar
false. but for right now, I know that the label.captions are located
in the vlookup table.
any help would be appreciated.

full code;
labLCPSF01.Caption
Application.WorksheetFunction.Sum(Application.WorksheetFunction.VLookup(labEDHght01.Caption
Workbooks("bidditdb.xls").Sheets("xl").Range("a3:b25"), 2, False)
Application.WorksheetFunction.VLookup(labEDFlr01.Caption
Workbooks("bidditdb.xls").Sheets("xl").Range("a3:b25"), 2, False)
Application.WorksheetFunction.VLookup(labEDMat01.Caption
Workbooks("bidditdb.xls").Sheets("mat").Range("a1:e200"), 5, False)
 
D

Don Guillett

try your
Application.WorksheetFunction.VLookup(label12.Caption,
Workbooks("1.xls").Sheets("1").Range("a3:b25"), 2, False)
by ITSELF to make sure it works.
If so, try leaving out the
Application.WorksheetFunction.Sum(

Sub addvlookups()'Example
mysum = Application.VLookup(1, Range("d1:e5"), 2) + _
Application.VLookup(2, Range("d1:e5"), 2) + _
Application.VLookup(3, Range("d1:e5"), 2)
MsgBox mysum
End Sub
 
G

GregJG

it is not working by itself, if it is a number only.

example

if label12.caption is "12" and a5 is "12" in
Workbooks("1.xls").Sheets("1").Range("a3:b25"), 2, False)
it will produce the error.

but, if I put a letter in front of value so label12.caption is "h12
and a5 is "h12" then it will produce what is in b5.

so, I am guessing it has to do with the data type of label12.caption
 
G

GregJG

from what I read, it has something to do with variable having to begi
with an alphabet.
I was able to fix by adding

dim myval as integer


myval=label12.caption

Application.WorksheetFunction.VLookup(myval
Workbooks("1.xls").Sheets("1").Range("a3:b25"), 2, False
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top