【发布时间】:2017-10-05 18:45:40
【问题描述】:
我正在使用以下代码来填充 ListBox。 ListBox 的第 1 列来自我的工作表的 F 列,而 ListBox 的第二列来自下一列。但我想让第二个 ListBox 列来自工作表的 D 列(左侧的 2)。而且我就是无法让偏移按我想要的方式工作。
Private Sub UserForm_Initialize()
Dim dic As Object
Dim rng As Range
Dim ky As Variant
Set dic = CreateObject("Scripting.Dictionary")
Set rng = Sheet4.Range("F2")
Do
If Not dic.exists(rng.Value) Then
dic.Add rng.Value, rng.Offset(, 1).Value
Else
dic(rng.Value) = dic(rng.Value) + rng.Offset(, 1).Value
End If
Set rng = rng.Offset(1)
Loop Until rng.Value = ""
For Each ky In dic.keys
With BWListBox3
.AddItem
.List(.ListCount - 1, 0) = ky
.List(.ListCount - 1, 1) = Application.Text(dic(ky), "[h]:mm")
End With
Next ky
End Sub
【问题讨论】:
标签: vba listbox offset userform