ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   error 1004 - application defined or object defined error (https://www.excelbanter.com/excel-programming/352656-error-1004-application-defined-object-defined-error.html)

kdp145

error 1004 - application defined or object defined error
 

i am getting this error when i execute the following code:

Workbooks("Raw Luggage Data.xls").Activate <-- executes fine

Sheets("Raw Luggage - 1").Select <--executes
fine
Range("A7").Select <---gives
error
ActiveCell.End(xlDown).Select
lastrow = ActiveCell.Row
MsgBox lastrow

this code is in a different file called "get data macro" and i have
this same exact code in a macro in "raw luggage data" where it works
fine. i also tried to comment out the 3rd line and then execute the
code and it works. the only prob is that i would have to manually
select cell A7. i dont know why it doesnt work? could it be becasue the
macro is in a diff file?

edit: lastrow is already declared


--
kdp145
------------------------------------------------------------------------
kdp145's Profile: http://www.excelforum.com/member.php...o&userid=29594
View this thread: http://www.excelforum.com/showthread...hreadid=509388


Mark Lincoln

error 1004 - application defined or object defined error
 
Is the code that fails in a module? I believe that if it's in one of
the worksheets it will fail.


Jim Thomlinson[_5_]

error 1004 - application defined or object defined error
 
You can try this. It avoids those pesky selects that can cause problems

lastrow = Workbooks("Raw Luggage Data.xls").Sheets("Raw Luggage -
1").Range("A7").End(xlDown).Row

msgbox lastrow
--
HTH...

Jim Thomlinson


"kdp145" wrote:


i am getting this error when i execute the following code:

Workbooks("Raw Luggage Data.xls").Activate <-- executes fine

Sheets("Raw Luggage - 1").Select <--executes
fine
Range("A7").Select <---gives
error
ActiveCell.End(xlDown).Select
lastrow = ActiveCell.Row
MsgBox lastrow

this code is in a different file called "get data macro" and i have
this same exact code in a macro in "raw luggage data" where it works
fine. i also tried to comment out the 3rd line and then execute the
code and it works. the only prob is that i would have to manually
select cell A7. i dont know why it doesnt work? could it be becasue the
macro is in a diff file?

edit: lastrow is already declared


--
kdp145
------------------------------------------------------------------------
kdp145's Profile: http://www.excelforum.com/member.php...o&userid=29594
View this thread: http://www.excelforum.com/showthread...hreadid=509388



Tom Ogilvy

error 1004 - application defined or object defined error
 
I agree with Jim, but this worked from a commandbutton on a worksheet in a
workbook other than Raw Luggage Data.xls

Private Sub CommandButton1_Click()
With Workbooks("Raw Luggage Data.xls")
.Activate
With .Sheets("Raw Luggage - 1")
.Select
.Range("A7").Select
End With
End With
ActiveCell.End(xlDown).Select
lastrow = ActiveCell.Row
MsgBox lastrow
End Sub

--
Regards,
Tom Ogilvy


"kdp145" wrote in
message ...

i am getting this error when i execute the following code:

Workbooks("Raw Luggage Data.xls").Activate <-- executes fine

Sheets("Raw Luggage - 1").Select <--executes
fine
Range("A7").Select <---gives
error
ActiveCell.End(xlDown).Select
lastrow = ActiveCell.Row
MsgBox lastrow

this code is in a different file called "get data macro" and i have
this same exact code in a macro in "raw luggage data" where it works
fine. i also tried to comment out the 3rd line and then execute the
code and it works. the only prob is that i would have to manually
select cell A7. i dont know why it doesnt work? could it be becasue the
macro is in a diff file?

edit: lastrow is already declared


--
kdp145
------------------------------------------------------------------------
kdp145's Profile:

http://www.excelforum.com/member.php...o&userid=29594
View this thread: http://www.excelforum.com/showthread...hreadid=509388




kdp145[_2_]

error 1004 - application defined or object defined error
 

thank you guys for the help. i followed mark's advice and moved my code
from the worksheet to the module and it worked like a charm. THANKS!!


--
kdp145
------------------------------------------------------------------------
kdp145's Profile: http://www.excelforum.com/member.php...o&userid=29594
View this thread: http://www.excelforum.com/showthread...hreadid=509388



All times are GMT +1. The time now is 01:45 PM.

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