Uniqe数组包含两个值

时间:2017-01-12 14:05:58

标签: arrays vba excel-vba unique dynamic-arrays

我有一行:

enter image description here

我想将此值添加到制表符/数组,以获得如下对:

[0] = Eng,3

[1] = PL,4

[2] =美国,5 ...

[x] = value,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

1 个答案:

答案 0 :(得分:4)

我建议使用二维数组代替存储单独的值。

<html>
<body>
    <form method="post" name="simple_upload" id="simple_upload" enctype="multipart/form-data" >
    <input type="file" id="file_to_upload" name="file_to_upload">
    <input type="submit" id="upload" name="upload" value="Upload" onmouseover="this.focus();">
    </body>
</html>

迭代以检查特定值..

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