Anzeige
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Anzeige
Inhaltsverzeichnis

Eintrag asu Listbox formatieren

Forumthread: Eintrag asu Listbox formatieren

Eintrag asu Listbox formatieren
15.01.2026 19:38:17
Dirk
Hallo liebe VBA-Experten,

ich benötige wieder einmal eure geschätzte Hilfe.

Aus einer Listbox wähle ich einen bestimmten Wert mit Listbox_Change aus.
Ein Wert dieser Auswahl soll mit Tausender-Trennzeichen, 2 Nachkommastellen
und Währungssysmbol in einem Label dargestellt werden.

Als Anhang mal der Code :


Option Explicit


Private Sub UserForm_Initialize()
Dim ws As Worksheet
Dim lastRow As Long
Dim lastCol As Long
Dim dataRange As Range
Dim dataArray As Variant
Dim lb As Object

Application.Visible = True

For Each lb In Me.Controls
If TypeName(lb) = "Label" Then lb.BackStyle = 0
Next lb

For Each lb In Me.Controls
If TypeName(lb) = "Label" Then lb.ForeColor = RGB(0, 0, 255)
Next lb

Set ws = ThisWorkbook.Sheets("Kunden")

lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
lastCol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column

Set dataRange = ws.Range("A2", ws.Cells(lastRow, lastCol))

dataArray = dataRange.Value

With Me.ListBox1
.Clear
.ColumnCount = lastCol
.List = dataArray
.ColumnCount = 27
.ColumnWidths = "2cm;3cm;2cm;0cm;1,5cm;4cm;4cm;4cm;1cm;1cm;5cm;0cm;0cm;0cm;2cm;4cm;4cm;2cm;2,5cm;0cm;0cm;0cm;0cm;0cm;0cm;0cm;0cm"
End With

With Me
.BackColor = RGB(211, 211, 211)
.Height = 255
.Width = 480
.StartupPosition = 2
.Caption = "Mandanten auswählen"
End With

With Me.CommandButton1
.Caption = "Datensatz übernehmen"
End With

With Me.Label1
.Visible = True
.Font.Size = 10
.Font.Bold = True
.TextAlign = 1
.ForeColor = RGB(0, 0, 0)
.Caption = "Bitte wählen Sie einen Mandanten aus !"
End With

With Me.Label2
.Font.Bold = True
.Font.Size = 10
End With

End Sub

Private Sub ListBox1_Change()
If ListBox1.Tag > "" Then Exit Sub
With UF_000
.Height = 435
.Label2.Caption = ListBox1.List(ListBox1.ListIndex, 0)
.Label3.Caption = ListBox1.List(ListBox1.ListIndex, 1)
.Label4.Caption = ListBox1.List(ListBox1.ListIndex, 2)
.Label5.Caption = ListBox1.List(ListBox1.ListIndex, 3)
.Label6.Caption = ListBox1.List(ListBox1.ListIndex, 4)
.Label7.Caption = ListBox1.List(ListBox1.ListIndex, 5)
.Label8.Caption = ListBox1.List(ListBox1.ListIndex, 6)
.Label9.Caption = ListBox1.List(ListBox1.ListIndex, 7)
.Label10.Caption = ListBox1.List(ListBox1.ListIndex, 8)
.Label11.Caption = ListBox1.List(ListBox1.ListIndex, 9)
.Label12.Caption = ListBox1.List(ListBox1.ListIndex, 10)
.Label13.Caption = ListBox1.List(ListBox1.ListIndex, 11)
.Label14.Caption = ListBox1.List(ListBox1.ListIndex, 12)
.Label15.Caption = ListBox1.List(ListBox1.ListIndex, 13)
.Label16.Caption = ListBox1.List(ListBox1.ListIndex, 14)
.Label17.Caption = ListBox1.List(ListBox1.ListIndex, 15)
.Label18.Caption = ListBox1.List(ListBox1.ListIndex, 16)
.Label19.Caption = ListBox1.List(ListBox1.ListIndex, 17)
.Label20.Caption = ListBox1.List(ListBox1.ListIndex, 18) 'soll mit Tausender-Trennzeichen mit 2 Nachkommastellen und Währungssymbol dargestellt werden !
.Label21.Caption = ListBox1.List(ListBox1.ListIndex, 19)
.Label22.Caption = ListBox1.List(ListBox1.ListIndex, 20)
.Label23.Caption = ListBox1.List(ListBox1.ListIndex, 21)
.Label24.Caption = ListBox1.List(ListBox1.ListIndex, 22)
.Label25.Caption = ListBox1.List(ListBox1.ListIndex, 23)
.Label26.Caption = ListBox1.List(ListBox1.ListIndex, 24)
.Label27.Caption = ListBox1.List(ListBox1.ListIndex, 25)
.Label28.Caption = ListBox1.List(ListBox1.ListIndex, 26)
End With
End Sub


Vielen Dank schon mal im Voraus

Grüße

Dirk
Anzeige

6
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Eintrag asu Listbox formatieren
15.01.2026 19:58:21
Alwin Weisangler
Hallo,

so was?
Format(ListBox1.List(ListBox1.ListIndex, 0),"#.##0,00")

Gruß Uwe
AW: Eintrag asu Listbox formatieren
15.01.2026 21:39:46
Alwin Weisangler
Hallo,
sorry, Punkt gegen Komma dann wirds richtig. Das passiert, wenn man dies am Tablet schreibt.
so richtig:
Format(ListBox1.List(ListBox1.ListIndex, i - 2), "#,##0.00")

Falls es nur darum geht würde dies ausreichen:


Private Sub ListBox1_Change()
Dim i&
If ListBox1.Tag > "" Then Exit Sub
With UF_000
.Height = 435
For i = 2 To 28
If IsNumeric(ListBox1.List(ListBox1.ListIndex, i - 2)) Then
.Controls("Label" & i).Caption = Format(ListBox1.List(ListBox1.ListIndex, i - 2), "#,##0.00")
Else
.Controls("Label" & i).Caption = ListBox1.List(ListBox1.ListIndex, i - 2)
End If
Next i
End With
End Sub


Gruß Uwe
Anzeige
AW: Eintrag asu Listbox formatieren
16.01.2026 17:48:39
Dirk
Hallo Uwe,
vielen Dank für die schnelle Antwort. jetzt habe ich auch wieder was
in Sachen Schleifen dazu gelernt. Das ist eine wirklich super Lösung
von Dir. Ist es aber möglich, daß nur der Wert für (Listbox1.Listindex, 18)
formatiert wird, da unter anderem Postleitzahlen sonst auch mit
formatiert werden ?

Vielen Dank im Voraus.

Grüße

Dirk
Anzeige
AW: Eintrag asu Listbox formatieren
16.01.2026 18:02:18
daniel
Hi
wenns nur ein Wert ist, würde ich erst alle Werte normal per Schleife übertragen und danach nochmal die, die eine spezielle Formatierung benötigen, einzeln.
ja ist prinzipiell doppeltarbeit, aber einfacher, also eine Schleife mit Ausnahmen und Sonderregelungen

Private Sub ListBox1_Change()

Dim i&
If ListBox1.Tag > "" Then Exit Sub
With UF_000
.Height = 435
For i = 2 To 28
.Controls("Label" & i).Caption = ListBox1.List(ListBox1.ListIndex, i - 2)
Next i
.Controls("Label" & i).Caption = Format(ListBox1.List(ListBox1.ListIndex, 18), "#,##0.00")
End With
End Sub


sollten es mehrere Spalten sein, die einen eigene Formtierung brauchen, dann so:
wenn noch weitere Spalten dieses Zahlenformat benötigen, dann die Indexnummer der Spalte mit Komma getrennt an das "Case 18" anfügen
Private Sub ListBox1_Change()

Dim i&
If ListBox1.Tag > "" Then Exit Sub
With UF_000
.Height = 435
For i = 2 To 28
Select Case i
Case 18
.Controls("Label" & i).Caption = Format(ListBox1.List(ListBox1.ListIndex, 18), "#,##0.00")
Case else
.Controls("Label" & i).Caption = ListBox1.List(ListBox1.ListIndex, i - 2)
end Select
Next i
End With
End Sub

Gruß Daniel
Anzeige
AW: Eintrag asu Listbox formatieren
16.01.2026 18:29:14
Dirk
Vielen Dank Euch allen,
das ist eine super Lösung. Habe noch ein & " €" angefügt, genau so wollte ich das !
AW: Eintrag asu Listbox formatieren
16.01.2026 18:17:13
Alwin Weisangler
Hallo,

Ja, so wie Daniel gezeigt. Wenn es jetzt noch anderer Formatierungen / Schleifen oder was auch immer bedarf, solltest du vielleicht mal die Datei anonymisiert hier hochladen.
Grundsätzlich stellt sich auch die Frage, ob dafür 2 Userforms überhaupt erforderlich sind.

Gruß Uwe
Anzeige

Forumthreads zu verwandten Themen

Anzeige