展开录制的“文本到列”macros

我正在尝试(与我的学习functionmacros一样多)把我录制的macros变成下面的函数。

我得到错误“没有数据被选中parsing”

我认为我的问题是Selection.TextToColumns Destination:=Cells(1, (cNum + 1)).Select在第二个Sub中Selection.TextToColumns Destination:=Cells(1, (cNum + 1)).Select 。 我不知道"iDel"是否是一个问题,因为我没有过去如何改变Destination:=Range("I1")

哪里:

cNum是要parsing的列
iCol是要插入的列数
iDel是parsing分隔符
iSn的图纸号码

任何见解都有帮助

这是固定的版本2 🙁这是最后一个版本(我不知道我可以把数组放在“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 

OP正确地确定了两个问题:

i)Selection.TextToColumns Destination:= Cells(1,(cNum + 1))。select和
ii)iDel

对于前者.Select是一个语法错误(在“设置目的地范围”时已经select了该列),对于后者, iDel已被定义为[string,而使用”iDel”将工作,如果需要的分隔符是i (因为单个字符是所有允许作为与文本到列的分隔符)。

现在反映在OP中的修复程序是删除。select和iDel周围的引号。