我看到了关于文本到列循环的 J.Con 的帖子(多列的文本到列 - Excel VBA)。但是,这仅在第一行包含所有信息时才有效,如第一张图片:
所以我改变了代码,让它像第二张图片一样工作。这是一种工作方式。只有我希望它像第三张图片一样工作,它找到单元格不为空白的最后一列,所以在这种情况下 cell("C3")
我使用的代码:
Dim LastRow As Long
LastRow = Cells.Find(What:="*", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
searchDirection:=xlPrevious, _
MatchCase:=False).Column
Dim LastColumn As Long
LastColumn = Cells.Find(What:="*", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
searchDirection:=xlPrevious, _
MatchCase:=False).Column
'Loops Text to columns
Dim StartingRow, StartingColumn As Long
StartingRow = 1
For StartingColumn = 1 To LastColumn
Range(Cells(StartingRow, StartingColumn), Cells(LastRow, StartingColumn)).Select
Selection.TextToColumns , DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=True, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Next