当为多个列执行文本到列时,空格似乎会影响分隔过程

我的第一个工作表包含一些填充列。 在底部,我有代码将这些列之一复制到第二个工作表并执行文本到列。 然后重复将另一列复制到第二个表中下一个可用列的过程。

问题:当代码遇到第二个工作表中特定列的第一个单元格中的空白时,文本到列的操作无法正常工作。

如果工作表1中的列(“粘贴”)如下所示:

------------------------------------------ Column 1 column 2 column 3 column 4 abcdefghijklmn 

在第2页(“TOP LINE”)中的文本到列之后,它错误地看起来像这样:

 --------------------------------------------------- C1 C2 C3 C4 C5 C6 C7 C8 abcdef ghijkn 

因此,在表1中列3中的单元格1被发现为空的情况下,列4中的表格2中的一些文本缺失(l和m已经消失)。 我认为这是从下面的代码到下面的行,但我不确定是诚实的。

  Selection.TextToColumns Destination:=Cells(1, b), DataType:=xlDelimited, 

任何帮助将不胜感激,我正在撕下我的头发与这一个!

 Sub TextToColumns() Dim a As Integer, b As Integer, cell As Range, column As Range Excel.Application.DisplayAlerts = False Excel.Sheets("TOP LINE").Select Cells.Select Cells.ClearContents For a = 1 To 60 If Application.WorksheetFunction.CountA(Excel.Sheets("Paste In").Columns(a)) > 0 Then Excel.Sheets("Paste In").Columns(a).Copy b = Excel.Sheets("TOP LINE").Cells(1, Columns.Count).End(Excel.xlToLeft).column Excel.Sheets("TOP LINE").Select If Application.WorksheetFunction.CountA(Excel.Sheets("TOP LINE").Columns(b)) > 0 Then b = b + 1 Excel.Sheets("TOP LINE").Columns(b).EntireColumn.Select Excel.ActiveSheet.Paste Excel.Application.CutCopyMode = False Selection.TextToColumns Destination:=Cells(1, b), DataType:=xlDelimited, _ TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, _ Semicolon:=False, Comma:=False, Space:=True, Other:=False, FieldInfo _ :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _ Array(7, 1), Array(8, 1)), TrailingMinusNumbers:=True End If Next a ActiveSheet.Columns.AutoFit ActiveSheet.Rows.AutoFit End Sub 

 Sub TextToColumns() Dim a As Integer, b As Integer Dim shtTop As Worksheet, shtPaste As Worksheet Dim wsf As WorksheetFunction Set wsf = Application.WorksheetFunction Set shtTop = ActiveWorkbook.Sheets("TOP LINE") Set shtPaste = ActiveWorkbook.Sheets("Paste In") Application.DisplayAlerts = False shtTop.Cells.ClearContents For a = 1 To 60 If wsf.CountA(shtPaste.Columns(a)) > 0 Then b = shtTop.Cells(1, Columns.Count).End(Excel.xlToLeft).Column Do While wsf.CountA(shtTop.Columns(b)) > 0 b = b + 1 Loop shtPaste.Columns(a).Copy shtTop.Cells(1, b) Application.CutCopyMode = False shtTop.Columns(b).TextToColumns Destination:=shtTop.Columns(b), _ DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _ ConsecutiveDelimiter:=True, Tab:=False, _ Semicolon:=False, Comma:=False, Space:=True, Other:=False, _ FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), _ Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1)), _ TrailingMinusNumbers:=True End If Next a With shtTop .Activate .Columns.AutoFit .Rows.AutoFit End With End Sub