Hi all
Need to accumualte values from a repeating Vlookup using VBA but cannot get the Vlookup to take dynamic ranges
Sub test()
Dim myrange As Range
Set mytable = Worksheets("sheet2").Range("A1:I10")
Dim accum, mycol, myrow, currentval, Collimit As Integer
'Inial position to look
mycol = 4
myrow = 1
accum = 0
On Error GoTo Tag:
colllimit = 0
Set myrange = Cells(myrow, mycol)
'Inner loop - set the value in the first cell, look across the columns
Do
currentval = Application.WorksheetFunction.VLookup(myrange, mytable, mycol, 0)
accum = accum + currentval
mycol = mycol + 1
Loop Until mycol = colllimit
ActiveCell.Value = accum
Tag:
MsgBox (Err.Number & " " & Err.Description)
End Sub
Gives error 1004, unable to get the vlookup propery of the worksheet funciton class
any ideas??
can I use this format?
ActiveCell.FormulaR1C1 = "=VLOOKUP(R[-1]C[-9],Sheet2!R[-3]C[-9]:R[6]C[-1],4,0)"
Need to accumualte values from a repeating Vlookup using VBA but cannot get the Vlookup to take dynamic ranges
Sub test()
Dim myrange As Range
Set mytable = Worksheets("sheet2").Range("A1:I10")
Dim accum, mycol, myrow, currentval, Collimit As Integer
'Inial position to look
mycol = 4
myrow = 1
accum = 0
On Error GoTo Tag:
colllimit = 0
Set myrange = Cells(myrow, mycol)
'Inner loop - set the value in the first cell, look across the columns
Do
currentval = Application.WorksheetFunction.VLookup(myrange, mytable, mycol, 0)
accum = accum + currentval
mycol = mycol + 1
Loop Until mycol = colllimit
ActiveCell.Value = accum
Tag:
MsgBox (Err.Number & " " & Err.Description)
End Sub
Gives error 1004, unable to get the vlookup propery of the worksheet funciton class
any ideas??
can I use this format?
ActiveCell.FormulaR1C1 = "=VLOOKUP(R[-1]C[-9],Sheet2!R[-3]C[-9]:R[6]C[-1],4,0)"