唯一数组包含两个值
Uniqe arrays contains two values
我有行:
我想将此值添加到 tab/arrays,以获得如下对:
[0] = 英语,3
[1] = PL, 4
[2] = 美国,5
...
[x] = 值,col_number
请告诉我怎么做:
1) 添加第二个值
2) 检查数组是否包含"Eng"或"PL"
到目前为止我有:
Dim CatTab() As Variant
Dim tabSize as Long
For b = 3 To 20
Category = wsSum.Cells(2, b).Value
tabSize = tabSize + 1
ReDim Preserve CatTab(tabSize)
CatTab(tabSize) = Category
Next
我建议使用二维数组来存储单独的值。
Dim CatTab As Variant
'First dimension can't be redimmed, use this for headers. Second dimension can, use this to extend data.
ReDim CatTab(1 To 2, 1 To 1)
Dim tabSize As Long
For b = 3 To 20
'Check if a resize is required
If CatTab(1, UBound(CatTab, 2)) <> "" Then ReDim Preserve CatTab(1 To UBound(CatTab, 1), 1 To UBound(CatTab, 2) + 1)
'Add value
CatTab(1, UBound(CatTab, 2)) = wssum.Cells(2, b)
'Add column
CatTab(2, UBound(CatTab, 2)) = b
Next
遍历以检查特定值..
Dim lng As Long
For lng = LBound(CatTab, 2) To UBound(CatTab, 2)
If InStr(1, CatTab(1, lng), "Eng") <> 0 Or InStr(1, CatTab(1, lng), "PL") <> 0 Then
'code here
End If
Next lng
我有行:
我想将此值添加到 tab/arrays,以获得如下对:
[0] = 英语,3
[1] = PL, 4
[2] = 美国,5 ...
[x] = 值,col_number
请告诉我怎么做:
1) 添加第二个值
2) 检查数组是否包含"Eng"或"PL"
到目前为止我有:
Dim CatTab() As Variant
Dim tabSize as Long
For b = 3 To 20
Category = wsSum.Cells(2, b).Value
tabSize = tabSize + 1
ReDim Preserve CatTab(tabSize)
CatTab(tabSize) = Category
Next
我建议使用二维数组来存储单独的值。
Dim CatTab As Variant
'First dimension can't be redimmed, use this for headers. Second dimension can, use this to extend data.
ReDim CatTab(1 To 2, 1 To 1)
Dim tabSize As Long
For b = 3 To 20
'Check if a resize is required
If CatTab(1, UBound(CatTab, 2)) <> "" Then ReDim Preserve CatTab(1 To UBound(CatTab, 1), 1 To UBound(CatTab, 2) + 1)
'Add value
CatTab(1, UBound(CatTab, 2)) = wssum.Cells(2, b)
'Add column
CatTab(2, UBound(CatTab, 2)) = b
Next
遍历以检查特定值..
Dim lng As Long
For lng = LBound(CatTab, 2) To UBound(CatTab, 2)
If InStr(1, CatTab(1, lng), "Eng") <> 0 Or InStr(1, CatTab(1, lng), "PL") <> 0 Then
'code here
End If
Next lng