我正在尝试(对于我的学习和功能宏一样多)将我录制的宏转换为以下函数。
我收到错误“未选择要解析的数据”
我认为我的问题Selection.TextToColumns Destination:=Cells(1, (cNum + 1)).Select
出在第二个子上。我不知道"iDel"
我写它的方式是否有问题,因为我没有过去如何改变Destination:=Range("I1")
在哪里:
cNum
是要解析
iCol
的列是要插入的列数是工作表编号中
iDel
的解析分隔符
iSn
任何见解都是有帮助的
这是固定版本2:( 这是最后一个版本(我不知道我可以将 Array 放在“fTexeToColumn”中试一试,它成功了)
Sub TexeToColumn()
'1st is the column to be parsed
'2nd is the number of columns to insert
'3rd is the parsing delimiter
'4th is the Sheet Number
'Array Set New Col Header Names, add as many name as 2nd parameter is equal to
fTexeToColumn "8", "3", "[", "2", Array("New Col Name1", "New Col Name2", "New Col Name3")
End Sub
Sub fTexeToColumn(cNum As Long, iCol As Long, iDel As String, iSn As Long, Headers As Variant)
'cNum is the column to be parsed
'iCol is the number of columns to insert
'iDel is the parsing delimiter
'iSn is the Sheet Number
Dim i As Long
Dim BaseWks As Worksheet
'~~> Set your sheet here
Sheets(iSn).Select
'~~>Adding Columns
For colx = 1 To iCol Step 1
Columns(cNum + colx).Insert Shift:=xlToRight
Next
'~~>Column to be parsed
Columns(cNum).Select
'~Set destination range here
Selection.TextToColumns Destination:=Cells(1, (cNum + 1)), DataType:=xlDelimited, _
TextQualifier:=xlNone, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:=iDel, FieldInfo:=Array(Array(1, 1), Array(2, 1)), TrailingMinusNumbers:=True
'~~>Delete original column
Columns(cNum).Delete
'Set Header Names
Set BaseWks = ThisWorkbook.Worksheets(iSn)
For i = LBound(Headers) To UBound(Headers)
BaseWks.Cells(1, i + cNum) = Headers(i)
Next i
End Sub