Bin wieder an die Grenzen meiner Programmierkunst gestossen...
Ich möchte eine sverweis-Formel mit fast ausschliesslich Variabeln erstellen. Die Werte der Variabeln sind teilweise aus einer ComboBox.
Ohne Verwendung der Variablen in der sverweis-Formel (Makro oben) funktionierts, mit den Variablen (Makro unten) leider nicht.
Habe etliche Forenbeiträge gelesen, doch leider habe ich es immer noch nicht geschaft, die Formel mit den Variablen korrekt darzustellen.
Für Eure Hilfe wäre ich sehr dankbar.
Sub SverweisUndVergleichsformelnEinsetzen1() 'so funktionierts
Dim Blatt1 As String
Dim Blatt2 As String
Dim BlattZiel As String
Dim azeile As String
Dim aspalte As Long
Blatt1 = ComboBox9.Value
Blatt2 = ComboBox10.Value
BlattZiel = ComboBox11.Value
Sheets(BlattZiel).Select
z = Sheets(BlattZiel).Cells(Rows.Count, 1).End(xlUp).Row
azeile = 1
aspalte = 2
Sheets(BlattZiel).Cells(azeile, aspalte).Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(C1,'" & Blatt1 & "'!C1:C2,2,0)" 'mit dieser Formel funktionierts
Selection.AutoFill Destination:=Range(Cells(azeile, aspalte), Cells(z, aspalte))
aspalte = aspalte + 1
Sheets(BlattZiel).Cells(azeile, aspalte).Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(C1,'" & Blatt2 & "'!C1:C2,2,0)"
Selection.AutoFill Destination:=Range(Cells(azeile, aspalte), Cells(z, aspalte))
End Sub
Und so funktionierts nicht:
Sub SverweisUndVergleichsformelnEinsetzen()
Dim u As String
Dim y As String
Dim z As String
Dim Blatt1 As String
Dim Blatt2 As String
Dim BlattZiel As String
Dim azeile As String
Dim aspalte As Long
Dim VergleichsspalteBis As Long
Dim VergleichsspalteVon As Long
Dim Keyspalte As Long
Blatt1 = ComboBox9.Value
Blatt2 = ComboBox10.Value
BlattZiel = ComboBox11.Value
Keyspalte = ComboBox16.Value
VergleichsspalteVon = ComboBox14.Value
VergleichsspalteBis = ComboBox15.Value
Sheets(BlattZiel).Select
u = Sheets(Blatt1).Cells(Rows.Count, 1).End(xlUp).Row
y = Sheets(Blatt2).Cells(Rows.Count, 1).End(xlUp).Row
z = Sheets(BlattZiel).Cells(Rows.Count, 1).End(xlUp).Row 'unterste gefüllte Zeile des Zielblattes
azeile = 1
aspalte = 2
Sheets(BlattZiel).Cells(azeile, aspalte).Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(C1,'" & Blatt1 & "'Cells(1 ,Keyspalte),cells(u, VergleichsspalteBis),VergleichsspalteVon,0)" 'hier ist der Wurm drin!
Selection.AutoFill Destination:=Range(Cells(azeile, aspalte), Cells(z, aspalte))
aspalte = aspalte + 1
Sheets(BlattZiel).Cells(azeile, aspalte).Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(C1,'" & Blatt2 & "'!C1:C2,2,0)"
Selection.AutoFill Destination:=Range(Cells(azeile, aspalte), Cells(z, aspalte))
End Sub