Hello there
I have found this one, but can't make my vlookup formula workring. Hope some can fix it up.
I got an error on this line: ws.Range(Cells(2, lngLastCol), Cells(lngLastRow - 1, lngLastCol)).Formula = "=IFERROR(SUM(" & Cells(2, lngLastCol - 1).Address(0, 0) & "*VLOOKUP(" & Cells(2, lngLastCol - 1).Address(0, 0) & "," & MasterSheet & "!A:G,3,FALSE)),"")"
The error is: Run-time error '1004': Application-defined or object-defined error.
MasterSheet is the sheet where we lookup for, and I want it to search for numbers in A column and should be multiply with the column before this vlookup. Hope some can fix my problem. Thanks!
I have found this one, but can't make my vlookup formula workring. Hope some can fix it up.
VBA Code:
Public Sub CreateSumFormulas()
Dim lngLastCol As Long, lngLastRow As Long
Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Ark45")
Dim StartCell As String: StartCell = "C2"
lngLastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row + 1
lngLastCol = ws.Cells(1, Columns.Count).End(xlToLeft).Column + 1
ws.Cells(lngLastRow, 1).Value = "Total"
ws.Cells(1, lngLastCol).Value = "Enheder Total"
ws.Range(Cells(2, lngLastCol), Cells(lngLastRow - 1, lngLastCol)).Formula = "=SUM(" & StartCell & ":" & Cells(2, lngLastCol - 1).Address(0, 0) & ")"
ws.Range(Cells(lngLastRow, 3), Cells(lngLastRow, lngLastCol)).Formula = "=SUM(" & StartCell & ":" & Cells(lngLastRow - 1, 3).Address(0, 0) & ")"
lngLastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row + 1
lngLastCol = ws.Cells(1, Columns.Count).End(xlToLeft).Column + 1
ws.Cells(1, lngLastCol).Value = "Værdi" 'Kolonne
ws.Range(Cells(2, lngLastCol), Cells(lngLastRow - 1, lngLastCol)).Formula = "=IFERROR(SUM(" & Cells(2, lngLastCol - 1).Address(0, 0) & "*VLOOKUP(" & Cells(2, lngLastCol - 1).Address(0, 0) & "," & MasterSheet & "!A:G,3,FALSE)),"")"
End Sub
I got an error on this line: ws.Range(Cells(2, lngLastCol), Cells(lngLastRow - 1, lngLastCol)).Formula = "=IFERROR(SUM(" & Cells(2, lngLastCol - 1).Address(0, 0) & "*VLOOKUP(" & Cells(2, lngLastCol - 1).Address(0, 0) & "," & MasterSheet & "!A:G,3,FALSE)),"")"
The error is: Run-time error '1004': Application-defined or object-defined error.
MasterSheet is the sheet where we lookup for, and I want it to search for numbers in A column and should be multiply with the column before this vlookup. Hope some can fix my problem. Thanks!