存储工作表中的值集合



伪代码:

If a=b then
result= a . cells(start,1).value
end if

如果列有多个匹配项,如何将这许多匹配值存储在变量中?以及如何将其添加到输入框中,用户可以在其中进行提示。

为什么不使用数组?(此代码完全未经测试)

Dim arrCount as Long
Dim temp() as Variant
arrCount = 1
If a = b then
    ReDim Preserve temp(1 to arrCount)
    temp(arrCount) = a.cells(start,1).value
    arrCount = arrCount + 1
End If
' Concatenate array together and separate by a semi-colon and a space for the delimiter character
InputBox.Value = Join(temp, "; ")

这可能有点矫枉过正,具体取决于您实际要实现的目标,但它将为您提供更多选择,然后仅将完整结果存储在变量中

If a=b then
    result= result & ";" & a.cells(start,1).value
end if

您可以考虑连接结果值(上面的示例显示了如何使 a=b 测试以分号分隔的值字符串

不过,您可能需要发布实际代码,以便可以适当地提供帮助。

最新更新