Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi all. Any idea why this line errors out if the sheet Data is not
the active sheet? If I run the code while on the Data sheet, all works well. If I run thwe code while on any other sheet, I get an "application defined or object defined error". Thanks! Set rng = Worksheets("Data").Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp)) |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sub routine()
Set rng = Worksheets("Data").Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp)) MsgBox (rng.Address) End Sub will work if: 1. there is a worksheet named Data 2. column A in that sheet has some data in it. -- Gary''s Student - gsnu2007e "Steve" wrote: Hi all. Any idea why this line errors out if the sheet Data is not the active sheet? If I run the code while on the Data sheet, all works well. If I run thwe code while on any other sheet, I get an "application defined or object defined error". Thanks! Set rng = Worksheets("Data").Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp)) |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
When you have an unqualified range in a general module, it will refer to the
activesheet. When you have an unqualified range in a worksheet module, it will refer to the sheet holding the code. so this will work Set rng = Worksheets("Data").Range(Worksheets("Data").Cells( 1, 1), _ Worksheets("Data").Cells(Rows.Count, 1).End(xlUp)) as will: with Worksheets("Data") Set rng = .Range(.Cells(1, 1), .Cells(Rows.Count, 1).End(xlUp)) End With I'd use: with Worksheets("Data") Set rng = .Range("A1", .Cells(.Rows.Count, 1).End(xlUp)) End With Steve wrote: Hi all. Any idea why this line errors out if the sheet Data is not the active sheet? If I run the code while on the Data sheet, all works well. If I run thwe code while on any other sheet, I get an "application defined or object defined error". Thanks! Set rng = Worksheets("Data").Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp)) -- Dave Peterson |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Awesome. Thanks guys!!
On Mar 4, 4:28*pm, Dave Peterson wrote: When you have an unqualified range in a general module, it will refer to the activesheet. When you have an unqualified range in a worksheet module, it will refer to the sheet holding the code. so this will work Set rng = Worksheets("Data").Range(Worksheets("Data").Cells( 1, 1), _ * * * * * * * Worksheets("Data").Cells(Rows.Count, 1).End(xlUp)) as will: with Worksheets("Data") * Set rng = .Range(.Cells(1, 1), .Cells(Rows.Count, 1).End(xlUp)) End With I'd use: with Worksheets("Data") * Set rng = .Range("A1", .Cells(.Rows.Count, 1).End(xlUp)) End With Steve wrote: Hi all. *Any idea why this line errors out if the sheet Data is not the active sheet? *If I run the code while on the Data sheet, all works well. *If I run thwe code while on any other sheet, I get an "application defined or object defined error". *Thanks! Set rng = Worksheets("Data").Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp)) -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
error 438 on For statement | Excel Programming | |||
Runtime Error - Subscript out of range despite On Error statement | Excel Programming | |||
For and IF statement error | Excel Programming | |||
Path/File access error (Error 75) using Name Statement | Excel Programming | |||
Path/File access error (Error 75) after using Name Statement | Excel Programming |