PDA

View Full Version : Solved: Range("A4").End(xlDown) Error



Opv
03-23-2010, 08:58 AM
I am receiving an error using the following code. I've noticed, however, that the error only occurs if the worksheet, "Transactions," is not the active worksheet. Is there a way to make this line of code work properly regardless worksheet tab that is selected?


Worksheets("Transactions").Range("A4").End(xlDown).Select

Bob Phillips
03-23-2010, 09:03 AM
If transactions is not active, you cannot select a range in that sheet, you have to activate it first.



With Worksheets("Transactions")

.Activate
.Range("A4").End(xlDown).Select
End With

Paul_Hossler
03-23-2010, 09:14 AM
Do you really need to select it? You can use the cell without selecting it first, regardless of which sheet is active



myVar = Worksheets("Transactions").Range("A4").End(xlDown).value


Paul

Opv
03-23-2010, 09:26 AM
If transactions is not active, you cannot select a range in that sheet, you have to activate it first.



With Worksheets("Transactions")

.Activate
.Range("A4").End(xlDown).Select
End With


Very good. Thanks, as always.

mdmackillop
03-23-2010, 10:58 AM
You can also use GoTo to select a range in the same or another open workbook.


Application.Goto Worksheets("Transactions").Range("A4").End(xlDown)
'or
Application.Goto Workbooks("Test.xls").Worksheets("Transactions").Range("A4").End(xlDown)
'or
Application.Goto Workbooks("Test.xls").Worksheets("Transactions").Range("Data")

Opv
03-23-2010, 11:00 AM
You can also use GoTo to select a range in the same or another open workbook.


Application.Goto Worksheets("Transactions").Range("A4").End(xlDown)
'or
Application.Goto Workbooks("Test.xls").Worksheets("Transactions").Range("A4").End(xlDown)



Thanks.