beginning programming: stop when last column in sheet
Sub Macro1()
Dim lastCol as Long
Dim i as Long
With Worksheets(1)
.Activate
lastCol = .Usedrange.columns( _
.UsedRange.columns.count).column
End with
For i = 1 To lastCol
Worksheets(1).Columns(i).Select
Selection.TextToColumns, DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 2), Array(20, 1)), _
TrailingMinusNumbers:=True
Next i
End Sub
--
Regards,
Tom Ogilvy
"David" wrote in message
...
Please help: I would like to change the hard coded 10 in the for loop to a
variable that represents the last column in the sheet.
Sub Macro1()
Worksheets(1).Activate
For i = 1 To 10
Worksheets(1)Columns(i).Select
Selection.TextToColumns , DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 2), Array(20, 1)),
TrailingMinusNumbers:=True
ActiveCell.Offset(columnOffset:=1).Select
Next i
End Sub
|