Hallo Leute,
ich habe hier folgenden Code erstellt, um eine Spalte aus Tabellenblatt 1 in 2 andere Tabellenblätter zu übertragen. Am Ende sollen die Werte aus Tabellenblatt 1 in insgesamt 10 Tabellenblätter übertragen werden. Brauche ich jetzt dafür immer 10 Deklarationen (z.B. a1,a2,a3,a4......, letzte1,letzte2,letzte3..) oder kann man das einfacher/eleganter lösen?
Danke im Voraus
Sub rueber()
Dim a1 As Variant
Dim a2 As Variant
Dim letzte1 As Long
Dim letzte2 As Long
Dim i As Long
Dim wksQ As Worksheet
Dim wksZ1 As Worksheet
Dim wksZ2 As Worksheet
Set wksQ = Worksheets("Beschreibung")
Set wksZ1 = Worksheets("X")
Set wksZ2 = Worksheets("Y")
letzte1 = wksZ1.Cells(wksZ1.Rows.Count, 3).End(xlUp).Row
letzte2 = wksZ2.Cells(wksZ2.Rows.Count, 3).End(xlUp).Row
For i = 1 To letzte1
a1 = Application.Match(wksZ1.Cells(i, 3), wksQ.Columns(2), 0)
If IsNumeric(a1) Then
wksZ1.Cells(i, 6).Value = wksQ.Cells(a1, 11).Value
Else
MsgBox "nicht vorhanden"
End If
Next
For i = 1 To letzte2
a2 = Application.Match(wksZ2.Cells(i, 3), wksQ.Columns(2), 0)
If IsNumeric(a2) Then
wksZ2.Cells(i, 6).Value = wksQ.Cells(a2, 11).Value
Else
MsgBox "nicht vorhanden"
End If
Next
Set wksQ = Nothing
Set wksZ1 = Nothing
Set wksZ2 = Nothing
End Sub
|