Eintrag asu Listbox formatieren
15.01.2026 19:38:17
Dirk
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