我尝试使用OtherChar
将文字添加到列中,而不仅限于一个。目前我的代码如下所示:
With Selection
.TextToColumns Destination:=[A2], _
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=True, _
Tab:=True, _
Semicolon:=False, _
Comma:=True, _
Space:=True, _
Other:=True, _
OtherChar:="-", _
TrailingMinusNumbers:=True
End With
但我希望OtherChar
包含这些字符"(, ), [, ], /, *"
。有没有办法做到这一点?
答案 0 :(得分:1)
快速而脏的代码。不要使用*作为分隔符,因为它将被视为全部替换
Dim aDelim
Dim delim
Dim oRange As Range
aDelim = Split("(,),[,],/", ",")
Set oRange = Selection
For Each delim In aDelim
oRange.Replace What:=delim, Replacement:="-"
Debug.Print oRange.Text, delim
Next
oRange.TextToColumns Destination:=[A2], _
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=True, _
Tab:=True, _
Semicolon:=False, _
Comma:=True, _
Space:=True, _
Other:=True, _
OtherChar:="-", _
TrailingMinusNumbers:=True