Vlookup mit Tabellenbereich - Fehler 1004 ungelöst
02.09.2024 12:38:11
VBANewbie
ich taste mich gerade an Makros ran und freue mich über das bisher gelernte.
Im Zuge eines Projektes habe ich diverse Formelmakros gebaut und genutzt, welche auf intelligente Tabellen zugreifen. Jetzt weigert sich jedoch das Makro einen Xverweis oder auch Sverweis auszuführen.
Händisch in die Zelle eingetragen funktionieren die Formeln. Alle Varianten haben zu dem gewünschten Ergebnis geführt.
Leider mag das Makro meine Formel W nicht und als Fehler gibt es immer die 1004.
Mit Support von Chat GPT komme ich ebenfalls nicht weiter und hoffe hier auf Schützenhilfe.
'Adding Formulas to Import Costs to elimante mixups due to several currencys
Sub CleanCurrencyImportCosts()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Import_Costs")
Dim lastrow As Long
' Find the last row with data in column A
lastrow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
'Define formula Names
Dim formulaT As String 'Sum of Contract costs
Dim formulaU As String 'Sum of Maintenance costs
Dim formulaV As String 'Sum of out of contract costs
Dim formulaW As String 'FDL1 in USD
Dim formulaX As String 'FDL2 in USD
Dim formulaY As String 'RFM in USD
Dim formulaZ As String 'GLC rate in USD
Dim formulaAA As String 'GLC Maintenance in USD
Dim formulaAB As String 'Maintenance in USD
Dim formulaAC As String 'Out of contract fees in USD
'Set formulas
formulaT = "=SUM(W2+x2+y2+z2)" 'Contract_fees = fdl1+fdl2+RFM_Miete+glc_rate
formulaU = "=SUM(AA2+Ab2)" 'GLC maintenance + Maintenance
formulaV = "=SUM(AC2)"
formulaW = "=ROUND(VLOOKUP(G2,Tabelle4[[#Alle];[Currency code]:[Exchange rate]],2,false)*F2,2)"
'Write formulas into cells
ws.Range("T2:T" & lastrow).Formula = formulaT
ws.Range("U2:U" & lastrow).Formula = formulaU
ws.Range("V2:V" & lastrow).Formula = formulaV
ws.Range("W2:W" & lastrow).Formula = formulaW
End Sub
Viele Grüße Alexandra eure VBANewbie
Anzeige