ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Range error (https://www.excelbanter.com/excel-discussion-misc-queries/199461-range-error.html)

Murray

Range error
 
I have an error occuring when I try to run this simple bit of code. The code
is:

Sheets("Name").select
Range("A2:D26").select

The code is started on Sheet1 and it does change to "Name" but it says :
select method of Range class failed.
The code is assigned to a button.

Any ideas what I have done wrong
Thanks in advance

Barb Reinhardt

Range error
 
I'd probably get rid of the SELECT altogether

Dim myWS as Worksheet
Dim myRange as range

On Error resume next
Set myWS = Sheets("Name")
On error goto 0
if myWS is nothing then
MsgBox("There is no worksheet 'Name'.")
End
end if

Set myRange = myWS.Range("A2:D26")

Do all of your action on myRange.
--
HTH,
Barb Reinhardt



"Murray" wrote:

I have an error occuring when I try to run this simple bit of code. The code
is:

Sheets("Name").select
Range("A2:D26").select

The code is started on Sheet1 and it does change to "Name" but it says :
select method of Range class failed.
The code is assigned to a button.

Any ideas what I have done wrong
Thanks in advance



All times are GMT +1. The time now is 02:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com