Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Louisville Cardinals
 
Posts: n/a
Default Help with this code... PLEASE!!!!!!

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
  #2   Report Post  
bj
 
Posts: n/a
Default

It looks ok.
If you haven't deleted the line and retyped it to insure thare aren't any
hidden code in the line, please try that.
You can also try to just select cell H4 and see if that works.
Another possibility is that Sheet 2 is protected. and won't let you select
becasue of that.

"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

  #3   Report Post  
AlfD
 
Posts: n/a
Default

Hi!

Which line does it crash on?

Are you calling the sub from one sheet and trying to pickup
Range("D52:D102") from a different (not active) sheet?

Alf

  #4   Report Post  
Louisville Cardinals
 
Posts: n/a
Default

It crashes on the line that reads Range("R4:AC22").Select

"AlfD" wrote:

Hi!

Which line does it crash on?

Are you calling the sub from one sheet and trying to pickup
Range("D52:D102") from a different (not active) sheet?

Alf


  #5   Report Post  
Dave Peterson
 
Posts: n/a
Default

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


  #6   Report Post  
Louisville Cardinals
 
Posts: n/a
Default

Thanks a bunch Dave. You are the MAN!!!!

"Dave Peterson" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Make Change Case in Excel a format rather than formula Kevin Excel Worksheet Functions 1 March 18th 05 08:53 PM
Error trapped only while stepping through the code - Not triggered when run Jeff Excel Discussion (Misc queries) 7 March 7th 05 06:29 PM
Opening a file with code without a set file name jenkinspat Excel Discussion (Misc queries) 1 March 4th 05 10:50 AM
Opening a file with code without a set file name jenkinspat Excel Discussion (Misc queries) 1 March 3rd 05 03:40 PM
Error trapped only while stepping through the code - Not triggered when run Jeff Excel Discussion (Misc queries) 0 February 28th 05 06:26 PM


All times are GMT +1. The time now is 03:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"