|
鄂龙蒙 发表于 2014-5-26 18:15
再请教一下:
下面的附件是用数组字典代码写的,有两个问题想请教一下。
Private Sub ComboBox1_Change()
Dim ITM As ListItem
Dim x As Range
Dim d, r&, i&, j&, k&, sn, arr, brr(), m&
Set d = CreateObject("Scripting.Dictionary")
With Worksheets("sheet1")
r = Sheet1.[E:E].Find("*", , xlValues, , , xlPrevious).Row '有数据的最后行数
arr = .Range("B5:I" & r)
m = Range("E:E").Find(ComboBox1.Text).Row - 4
ReDim brr(1 To UBound(arr) + 1, 1 To 8)
For k = m To UBound(arr)
If k > 0 Then '这个判断怎么加?-------另一个问题是当选择“编号”1时,第1行不显示。
i = i + 1
brr(i, 1) = arr(k, 2): brr(i, 2) = arr(k, 3): brr(i, 3) = arr(k, 5)
brr(i, 4) = arr(k, 6): brr(i, 5) = arr(k, 7): brr(i, 6) = arr(k, 8)
sn = sn + brr(i, 6) * 1
End If
brr(i + 1, 4) = " 合 计" '没有上面 K>1 的判断,到这里显示----越界
brr(i + 1, 6) = sn
Next k
End With
UserForm1.ListView1.ListItems.Clear
For i = 1 To UBound(brr)
'添加记录
Set ITM = ListView1.ListItems.Add()
'添加内容
ITM.Text = brr(i, 1)
ITM.SubItems(1) = brr(i, 2)
ITM.SubItems(2) = brr(i, 3)
ITM.SubItems(3) = brr(i, 4)
ITM.SubItems(4) = brr(i, 5)
ITM.SubItems(5) = brr(i, 6)
Next i
Set ITM = Nothing
End Sub |
|