简体   繁体   English

文本到列VBA目标到新工作表

[英]Text To Columns VBA Destination onto new sheet

I'm having a problem with Excel VBA Text To Columns. 我在使用Excel VBA文本到列时遇到问题。 Apparently the function is fixated on putting the destination on the same sheet when I want it to be on a new sheet. 显然,该功能已固定在我希望将目标放置在新表上的同一张表上。

Worksheets("RawData").Columns(ID).TextToColumns Destination:=Worksheets("Regular").Columns("C"), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
    Semicolon:=False, Comma:=True, Space:=False, Other:=True, _
    OtherChar:="(", _
    FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1)), TrailingMinusNumbers:=True

Apparently this will just dump it on Column C of raw data rather than the worksheet of "Regular" where i want it to be. 显然,这只会将其转储到原始数据的C列中,而不是我想要的“常规”工作表中。

Another approach would be using string manipulation directly. 另一种方法是直接使用字符串操作。 Assuming you want the colon to be your delimiter in the text to column command: 假设您希望冒号成为text to column命令中的定界符:

dim i as integer
dim j as integer
dim strTemp as string
dim arrString() as string

for i = 1 to 'number of rows in your first sheet
    strTemp = cells(i, 1)
    arrStrings = strings.split(strTemp, ",")
    for j = 1 to ubound(arrStrings)
        sheet2.cells(i, j) = arrStrings(j)
    next j
next i

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM