所以基本上我有多列文本要转换为数字。 现在我面临的问题是我得到了代码,但我不明白如何在它上面运行循环来选择下一个第三列。 这是我的代码:
Sub Texscolumn()
Range("AI2:AI96").Select
Selection.TextToColumns Destination:=Range("AI2"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=True, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 9), Array(3, 9), Array(4, 9), Array(5, 9), Array(6, 9), Array(7, 9), Array(8, 9)), TrailingMinusNumbers:= _
True
End Sub
所以我想要的下一栏是AJ2:AJ96。 我似乎无法弄清楚如何使用像这样更改列来创建for循环。
答案 0 :(得分:1)
至少有两个选项:
Sub Texscolumn()
Dim j As Integer
With Sheets("sheet1")
For j = 35 To 36
.Range(.Cells(2, j), .Cells(96, j)).TextToColumns Destination:=.Cells(2, j), _
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=True, _
Tab:=True, _
Semicolon:=False, _
Comma:=False, _
Space:=True, _
Other:=False, _
FieldInfo:=Array(Array(1, 1), Array(2, 9), Array(3, 9), Array(4, 9), Array(5, 9), Array(6, 9), Array(7, 9), Array(8, 9)), _
TrailingMinusNumbers:=True
Next i
End With
End Sub
或
Sub Texscolumn()
Dim Rg As Range
Dim i As Integer
Set Rg = Sheets("sheet1").Range("AI2:AI96")
With Rg
For i = 1 To 2
.TextToColumns Destination:=.Cells(1, 1), _
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=True, _
Tab:=True, _
Semicolon:=False, _
Comma:=False, _
Space:=True, _
Other:=False, _
FieldInfo:=Array(Array(1, 1), Array(2, 9), Array(3, 9), Array(4, 9), Array(5, 9), Array(6, 9), Array(7, 9), Array(8, 9)), _
TrailingMinusNumbers:=True
Set Rg = .Offset(0, 1)
Next i
End With
End Sub