Wie kann ich die Quelladresse (zum Beispiel "A2") einer Listbox-Auswahl in einer MsgBox rausgeben?
Besten Dank für die Vorschläge.
Gruss Daniel
Private Sub UserForm_Initialize()
Dim rngBereich As Range
Dim ws As Worksheet
Set ws = Worksheets(10)
With ListBox1
.ColumnCount = 4
.ColumnWidths = "180;180;100;10" 'Länge der Spalte
.Font.Size = 12
For Each rngBereich In ws.Range("A2:A25")
If rngBereich.Font.ColorIndex = 3 Then
.AddItem rngBereich.Text
.List(.ListCount - 1, 1) = rngBereich.Offset(, 1).Text
.List(.ListCount - 1, 2) = rngBereich.Offset(, 2).Text
.List(.ListCount - 1, 3) = rngBereich.Offset(, 3).Text
End If
Next rngBereich
End With
End Sub
Nun sollte nach der Auswahl die Quelle als Code (z.B. "B7") in eine MsgBox geschrieben werden!
Option Explicit
Private Sub ListBox1_Click()
With ListBox1
MsgBox .List(.ListIndex, 4)
End With
End Sub
Private Sub UserForm_Initialize()
Dim rngBereich As Range
Dim ws As Worksheet
Set ws = Worksheets(10)
With ListBox1
.ColumnCount = 5
.ColumnWidths = "180;180;100;10;0" 'Breite der Spalte
.Font.Size = 12
For Each rngBereich In ws.Range("A2:A25")
If rngBereich.Font.ColorIndex = 3 Then
.AddItem rngBereich.Text
.List(.ListCount - 1, 1) = rngBereich.Offset(, 1).Text
.List(.ListCount - 1, 2) = rngBereich.Offset(, 2).Text
.List(.ListCount - 1, 3) = rngBereich.Offset(, 3).Text
.List(.ListCount - 1, 4) = rngBereich.Address
End If
Next rngBereich
End With
End Sub
Gruess Hansueli
.List(.ListCount - 1, 4) = rngBereich.Row
.List(.ListCount - 1, 5) = rngBereich.Column
Dann hast du statt der Adresse Zeilen- und Spaltennummern in der Liste.
Cells(.List(.Listindex, 4), CLng(.List(.ListIndex, 5)))
Gruß Daniel