【发布时间】:2019-01-18 00:06:44
【问题描述】:
我的代码将 excel 中表格的所有值复制到数组上,然后过滤它们并用它填充组合框,但我的代码不断收到此错误,调试后似乎该错误是由于 Redim Preserve 造成的。 ..你能检查一下吗?
' FIll CB2()
Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("D1")
Dim LC As Long
Dim i As Long
Dim PN As Long
Dim myArray() As String
Dim j As Long
Dim k As Long
Dim temp As String
LC = ws.Cells(ws.Rows.Count, 4).End(xlUp).Row
For i = 1 To LC
If StrComp(CB1.List(CB1.ListIndex, 0), ws.Cells(i, 4), vbTextCompare) = 0 Then
'Set you array with the right dimension
ReDim Preserve myArray(0 To PN, 0 To 1)
myArray(PN, 0) = ws.Cells(i, 2)
myArray(PN, 1) = ws.Cells(i, 3)
PN = PN + 1
End If
Next i
End Sub
【问题讨论】:
标签: arrays excel vba dynamic-programming