1

所以基本上我有多列文本要更改为数字。现在我面临的问题是我得到了代码,但我不明白如何在它上面运行一个循环来选择下一个第三列。这是我的代码:

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 循环。

4

1 回答 1

1

至少 2 个选项:

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
于 2017-02-01T11:15:34.283 回答