string数组到新的工作表

下面的代码执行和拆分原始单元格到一个新的数组,但我不能让新的string数组移动到一个新的工作表。 引发错误的行是varHorizArray(1,intCol).Select。 如何改变这个代码直接将数组移动到一个新的工作表? 我想search新的数组中的单词。

Sub SplitWithFormat() Dim R As Range, C As Range Dim i As Long, V As Variant Dim varHorizArray As Variant Dim rge As Range Dim intCol As Integer Set R = Range("d1", Cells(Rows.Count, "d").End(xlUp)) For Each C In R With C .TextToColumns Destination:=.Offset(0, 1), DataType:=xlDelimited, _ consecutivedelimiter:=True, Tab:=False, semicolon:=True, comma:=False, _ Space:=True, other:=True, Otherchar:=vbLf Set rge = Selection varHorizArray = rge .Copy Range(.Offset(0, 1), Cells(.Row, Columns.Count).End(xlToLeft)).PasteSpecial xlPasteFormats End With Next C Application.CutCopyMode = False For intCol = LBound(varHorizArray, 2) To UBound(varHorizArray, 2) Debug.Print varHorizArray(1, intCol) Next intCol Sheets("Sheet1").Activate varHorizArray(1, intCol).Select ActiveSheet.Paste End Sub ​ 

要直接将数组转储到工作表,只需设置与您的数组具有相似维度的范围,然后将该数组分配给该范围即可。

 Sheet1.Activate Sheet1.Range(Cells(1, LBound(varHorizArray, 2)), Cells(UBound(varHorizArray), UBound(varHorizArray, 2))) = varHorizArray