I'm betting your code is behind a worksheet--maybe associated with a
commandbutton???
If that's true, then the problem is that unqualifed ranges refer to the sheet
with the code--not the selected sheet.
But you don't usually have to select a range to work with it:
Option Explicit
Private Sub CommandButton1_Click()
With Me
.Range("D52:D102").TextToColumns Destination:=.Range("D52"), _
DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), _
Array(14, 1), Array(21, 1), Array(27, 1), Array(32, 1), _
Array(38, 1), Array(43, 1), Array(45, 1), Array(47, 1), _
Array(49, 1), Array(51, 1), Array(53, 1), Array(55, 1), _
Array(57, 1), Array(59, 1), Array(61, 1), Array(63, 1)), _
TrailingMinusNumbers:=True
.Range("R4:AC22").Copy
Worksheets("sheet2").Range("H4").PasteSpecial _
Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
End With
Worksheets("sheet2").PrintOut Copies:=3, Collate:=True
End Sub
Louisville Cardinals wrote:
I have the following code to convert a colum to text then copy the new
information to sheet 2. I keep getting an error message that says "Select
Method of Range Class Failed" on the line "Range("H4:S22").Select".
Range("D52:D102").Select
Application.CutCopyMode = False
Selection.TextToColumns Destination:=Range("D52"),
DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(14, 1), Array(21, 1), Array(27,
1), Array(32, 1), _
Array(38, 1), Array(43, 1), Array(45, 1), Array(47, 1), Array(49,
1), Array(51, 1), Array( _
53, 1), Array(55, 1), Array(57, 1), Array(59, 1), Array(61, 1),
Array(63, 1)), _
TrailingMinusNumbers:=True
Range("R4:AC22").Select
Selection.Copy
Sheets("Sheet2").Select
Range("H4:S22").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWindow.SelectedSheets.PrintOut Copies:=3, Collate:=True
--
Dave Peterson
|