VBA:分裂和连接数组和string
我正在处理一组看起来像这样的单元格:
我想要做的是通过每个国家的国家/地区列进行过滤,然后将每个制造商都join到一起,以便我们可以在另一个工作簿中筛选它们。
所以基本上,我想Join(m1, m2, m3)
,这就是我想要做到的:
xRange
是“制造商缩写”的栏目。 我也有If xCell... <> "" Then
因为没有“上一个制造商缩写”在xRange
所有条目
Dim tempMfr As String Dim temp2Mfr As String Dim stringArray() As String Dim arraytostring As String For Each xCell In xRange tempMfr = xCell If xCell.Offset(0, 2) <> "" Then temp2Mfr = xCell.Offset(0, 2) stringArray() = Split(temp2Mfr, ", ") arraytostring = Join(temp2Mfr & stringArray, ", ") stringArray() = Split(arraytostring, ", ") For x = LBound(stringArray) To UBound(stringArray) MsgBox (stringArray(x)) Next End If Next
我的问题来自行Join(temp2Mfr & stringArray)
由于&
创buildtypes不匹配编译错误。
我也试过:
ReDim Preserve stringArray(0 to (UBound(stringArray) + 1)) stringArray(UBound(stringArray)) = temp2Mfr
一旦我得到了整理,我打算在另一个工作簿中使用search,看起来像这样:
Cells.AutoFilter Field:=4, Criteria1:= Array(MfrArray)
非常感谢您的帮助。
在Join甚至执行之前,您正试图将string连接到您的数组。
这是不允许的,是什么导致你的错误。
你可以这样做:
Redim Preserve stringArray(Ubound(stringArray) + 1) stringArray(Ubound(stringArray)) = temp2Mfr
根本不需要Join()。