Run-time Error 1004’ - Range("A1").Select

P

Paul

Hi All,

While stepping through the following Excel Code, a ‘Run-time Error 1004’
with an ‘Application-defined or object-defined error’ statement is returned.
What’s the reason and correction required?

Sub DailyTotal_Fourth()
'Start Summary Data
'Day verification info

Application.ScreenUpdating = False
Windows("Daily Time Sheet.xls").Activate
Sheets("Daily Detail Production").Select
Range("B2").Select
Sheets("Total").Select
Range("A1").Select

End sub

Thx
Paul
 
D

Dave Peterson

Is this code in a general module or behind a worksheet?

if it's behind a worksheet, then an unqualified range (like range("b2")) refers
to the sheet that owns the code--not the activesheet.

Sub DailyTotal_Fourth()
'Start Summary Data
'Day verification info

Application.ScreenUpdating = False
with workbooks("Daily Time Sheet.xls")
with .worksheets("Daily Detail Production")
.select
.range("b2").select
end with
with .worksheets("total")
.select
.range("a1").select
end with
end with
End sub

But it's pretty rare that you have to select a range to do things to it:

workbooks("daily time sheet.xls").worksheets("daily detail production") _
.range("B2").value = "hi there!"

might be an alternative.
 
Top