【发布时间】:2021-08-25 01:30:00
【问题描述】:
如何将总列值以货币表示(例如 $27265,28),搜索我找到了代码 .AddItem Format(Cell.Value, "$#,##0.00") 但它不起作用,我需要将 Listbox 列格式化为货币 ("$#,##0.00).
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub Label1_Click()
End Sub
Private Sub TextBox1_Change()
Me.TextBox1 = Format(StrConv(Me.TextBox1, vbLowerCase))
Dim sh As Worksheet
Set sh = Sheets("Sheet1")
Dim i As Long
Dim x As Long
Dim p As Long
Me.ListBox1.Clear
For i = 2 To sh.Range("B" & Rows.Count).End(xlUp).Row
For x = 1 To Len(sh.Cells(i, 2))
p = Me.TextBox1.TextLength
If LCase(Mid(sh.Cells(i, 2), x, p)) = Me.TextBox1 And Me.TextBox1 <> "" Then
With Me.ListBox1
.AddItem sh.Cells(i, 2)
.List(ListBox1.ListCount - 1, 1) = sh.Cells(i, 3)
.List(ListBox1.ListCount - 1, 2) = sh.Cells(i, 4)
.List(ListBox1.ListCount - 1, 3) = sh.Cells(i, 5)
.List(ListBox1.ListCount - 1, 4) = sh.Cells(i, 6)
.List(ListBox1.ListCount - 1, 5) = sh.Cells(i, 7)
End With
End If
Next x
Next i
End Sub
【问题讨论】:
-
cstr(Format(cell.Value, "$#,##0.00"))有效吗?我已经试过你的代码,它对我来说没问题。 -
顺便说一句,您应该在
End With和End If之前插入一个Exit For,以避免可能多次显示同一事件。 @MarcMelo -
我忘了告诉你它在列表框中,但感谢你的时间帮助我