AW: Sverweis mit VBA
27.04.2005 22:56:50
Beate
Hallo Gisela,
füge diesen Code ins Codefenster von Tabelle2 ein:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
Application.EnableEvents = False
Dim rngB As Range
Set rngB = Sheets("Tabelle1").Range("A:J")
Cells(Target.Row, 2).Value = Application.WorksheetFunction.Testefehler(VLookup(Cells(ActiveCell.Row, 1), rngB, 2, False))
Cells(Target.Row, 3).Value = Application.WorksheetFunction.Testefehler(VLookup(Cells(ActiveCell.Row, 1), rngB, 3, False))
Cells(Target.Row, 4).Value = Application.WorksheetFunction.Testefehler(VLookup(Cells(ActiveCell.Row, 1), rngB, 4, False))
Cells(Target.Row, 5).Value = Application.WorksheetFunction.Testefehler(VLookup(Cells(ActiveCell.Row, 1), rngB, 5, False))
Cells(Target.Row, 6).Value = Application.WorksheetFunction.Testefehler(VLookup(Cells(ActiveCell.Row, 1), rngB, 6, False))
Cells(Target.Row, 7).Value = Application.WorksheetFunction.Testefehler(VLookup(Cells(ActiveCell.Row, 1), rngB, 7, False))
Cells(Target.Row, 8).Value = Application.WorksheetFunction.Testefehler(VLookup(Cells(ActiveCell.Row, 1), rngB, 8, False))
Cells(Target.Row, 9).Value = Application.WorksheetFunction.Testefehler(VLookup(Cells(ActiveCell.Row, 1), rngB, 9, False))
Cells(Target.Row, 10).Value = Application.WorksheetFunction.Testefehler(VLookup(Cells(ActiveCell.Row, 1), rngB, 10, False))
Application.EnableEvents = True
End If
End Sub
Deine Funktion Testefehler kenne ich ja nicht, von daher habe ich meinen Code ohne sie getestet und da lief er. Bei Eingabe in Tabelle2! Spalte A wird nun in der aktiven Zeile Spalten B:J jeweils der entsprechende Sverweis aus Tabelle 1 Spalte A:J genommen.
Gruß,
Beate