Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Coolboy55
 
Posts: n/a
Default Selecting a Worksheet Range


This is my code:

-Sheet4.Range("A3", Cells(l_LastRow, l_LastColumn)).Select-

I get the error message: "Method 'Range' of object '_Worksheet'
failed"

It's a runtime error 1004.

I get this error whenever the active sheet is any sheet besides
Sheet4, and using Worksheets("SheetName") in place of Sheet4 doesn't
work either, instead getting an "Application-defined or object-defined
error."

What's going on?


--
Coolboy55
------------------------------------------------------------------------
Coolboy55's Profile: http://www.excelforum.com/member.php...o&userid=26508
View this thread: http://www.excelforum.com/showthread...hreadid=397878

  #2   Report Post  
Bernie Deitrick
 
Posts: n/a
Default

Coolboy55,

You can't select a range on an inactive worksheet. Since you rarely need to select, change your
code to get rid of the .Select commands, or change the code to select sheet4 first.

HTH,
Bernie
MS Excel MVP


"Coolboy55" wrote in message
...

This is my code:

-Sheet4.Range("A3", Cells(l_LastRow, l_LastColumn)).Select-

I get the error message: "Method 'Range' of object '_Worksheet'
failed"

It's a runtime error 1004.

I get this error whenever the active sheet is any sheet besides
Sheet4, and using Worksheets("SheetName") in place of Sheet4 doesn't
work either, instead getting an "Application-defined or object-defined
error."

What's going on?


--
Coolboy55
------------------------------------------------------------------------
Coolboy55's Profile: http://www.excelforum.com/member.php...o&userid=26508
View this thread: http://www.excelforum.com/showthread...hreadid=397878



  #3   Report Post  
Bernie Deitrick
 
Posts: n/a
Default

Coolboy55,

I should also have mentioned that when you get rid of your select statements, you need to pay
attention to your range objects, since an unqualified range object defaults to the active sheet.
The range in your statement:

Sheet4.Range("A3", Cells(l_LastRow, l_LastColumn)).Select

would be better written (without the select) as

Sheet4.Range("A3", Sheet4.Cells(l_LastRow, l_LastColumn))

HTH,
Bernie
MS Excel MVP


"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Coolboy55,

You can't select a range on an inactive worksheet. Since you rarely need to select, change your
code to get rid of the .Select commands, or change the code to select sheet4 first.

HTH,
Bernie
MS Excel MVP


"Coolboy55" wrote in message
...

This is my code:

-Sheet4.Range("A3", Cells(l_LastRow, l_LastColumn)).Select-

I get the error message: "Method 'Range' of object '_Worksheet'
failed"

It's a runtime error 1004.

I get this error whenever the active sheet is any sheet besides
Sheet4, and using Worksheets("SheetName") in place of Sheet4 doesn't
work either, instead getting an "Application-defined or object-defined
error."

What's going on?


--
Coolboy55
------------------------------------------------------------------------
Coolboy55's Profile: http://www.excelforum.com/member.php...o&userid=26508
View this thread: http://www.excelforum.com/showthread...hreadid=397878





  #4   Report Post  
Coolboy55
 
Posts: n/a
Default


Thank you Bernie! You have been a great help.

What is the usual method for applying borders and shading to certain
cells if not by selecting? I had the feeling I was doing it the long
way, but it didn't occur to me immediately that there was a better way.


--
Coolboy55
------------------------------------------------------------------------
Coolboy55's Profile: http://www.excelforum.com/member.php...o&userid=26508
View this thread: http://www.excelforum.com/showthread...hreadid=397878

  #5   Report Post  
Bernie Deitrick
 
Posts: n/a
Default

Coolboy55,

See the sample code below.

HTH,
Bernie
MS Excel MVP

Sub Macro2()
With Worksheets("Sheet2").Range("A1:B10")
With .Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
End With
End Sub


"Coolboy55" wrote in message
...

Thank you Bernie! You have been a great help.

What is the usual method for applying borders and shading to certain
cells if not by selecting? I had the feeling I was doing it the long
way, but it didn't occur to me immediately that there was a better way.


--
Coolboy55
------------------------------------------------------------------------
Coolboy55's Profile: http://www.excelforum.com/member.php...o&userid=26508
View this thread: http://www.excelforum.com/showthread...hreadid=397878





  #6   Report Post  
William Horton
 
Posts: n/a
Default

You may have to reference the proper sheet again just before Cells(l_Last.....
Try Sheet4.Cells(l_La....
and see if that works.

Bill Horton

"Coolboy55" wrote:


This is my code:

-Sheet4.Range("A3", Cells(l_LastRow, l_LastColumn)).Select-

I get the error message: "Method 'Range' of object '_Worksheet'
failed"

It's a runtime error 1004.

I get this error whenever the active sheet is any sheet besides
Sheet4, and using Worksheets("SheetName") in place of Sheet4 doesn't
work either, instead getting an "Application-defined or object-defined
error."

What's going on?


--
Coolboy55
------------------------------------------------------------------------
Coolboy55's Profile: http://www.excelforum.com/member.php...o&userid=26508
View this thread: http://www.excelforum.com/showthread...hreadid=397878


  #7   Report Post  
William Horton
 
Posts: n/a
Default

Sorry....Check that last reply. You have to activate the sheet before you
can select.

"William Horton" wrote:

You may have to reference the proper sheet again just before Cells(l_Last.....
Try Sheet4.Cells(l_La....
and see if that works.

Bill Horton

"Coolboy55" wrote:


This is my code:

-Sheet4.Range("A3", Cells(l_LastRow, l_LastColumn)).Select-

I get the error message: "Method 'Range' of object '_Worksheet'
failed"

It's a runtime error 1004.

I get this error whenever the active sheet is any sheet besides
Sheet4, and using Worksheets("SheetName") in place of Sheet4 doesn't
work either, instead getting an "Application-defined or object-defined
error."

What's going on?


--
Coolboy55
------------------------------------------------------------------------
Coolboy55's Profile: http://www.excelforum.com/member.php...o&userid=26508
View this thread: http://www.excelforum.com/showthread...hreadid=397878


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
How do I reduce the range of a saved worksheet? John Britten Excel Discussion (Misc queries) 3 September 4th 08 09:46 AM
macro help thephoenix12 Excel Discussion (Misc queries) 4 July 15th 05 05:57 PM
Search Range for Criteria in given cell and produce results RFreeman12 Excel Discussion (Misc queries) 3 June 27th 05 09:23 PM
can bin range for histograms be on a different worksheet? onereallyfrustratedcamper Excel Discussion (Misc queries) 1 May 20th 05 07:08 AM
toggling which worksheet a named range refers to Loftus Excel Discussion (Misc queries) 0 March 30th 05 12:05 AM


All times are GMT +1. The time now is 01:56 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"