用户窗体百分比列表框?

我在一个用户窗体中使用一个列表框,它显示一个格式为百分比的列中的唯一值。 我通过使用字典对象生成一个唯一的列表/值,并将其提供给一个列表框。

我的问题是所有的值都显示为列表框中的十进制数字而不是百分比。 任何想法如何以百分比/格式显示他们?

参考:列表框值可以改变取决于用户select文本/数字/date/货币/百分比

唯一的列表代码

Sub UniqData(fString As String, cbNr As Integer) ' fString as string Dim d As Object With Sheets("xxx") cNr = WorksheetFunction.Match(fString, .Rows(1), 0) lRo = .Cells(Rows.Count, 1).End(xlUp).Row arrD = .Range(.Cells(2, cNr), .Cells(lRo, cNr)) Set d = CreateObject("scripting.dictionary") For Each c In arrD If Len(c) > 0 Then d00 = dic.Item(c.Text) End If Next c k = d.keys End With UserForm1.Controls("lb" & cbNr).List = k End Sub 

喜欢这个。

使用电子表格格式化单元格只会修改数字将如何呈现给用户。 基本价值保持不变。

因此,您需要将值明确地格式化为您希望它看起来像你正在添加字典。

 d.Add Format(c, "0.0%"), c 

正如@Meehow所提到的,如果数据太大而不能显示在单元格中,则使用c.Text可能会产生错误!

因此,在d.Add行中使用Format(c.Value, "0.0%")作为关键字,您将从Excel单元格中获得格式:Sub UniqData(fString As String,cbNr As Integer)'fString as string Dim d作为对象

 With Sheets("xxx") cNr = WorksheetFunction.Match(fString, .Rows(1), 0) lRo = .Cells(Rows.Count, 1).End(xlUp).Row arrD = .Range(.Cells(2, cNr), .Cells(lRo, cNr)) Set d = CreateObject("scripting.dictionary") For Each c in arrD d.Add Format(c.Value, c.NumberFormat), c.Value Next c k = d.keys End With UserForm1.Controls("lb" & cbNr).List = k End Sub