Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default App Defined or Object defined error

You could try declaring lastrow and startrow as integer (or long) instead of single.

David


"Marcotte A" wrote in message ...
I have a worksheet with 18 pages, one for each store. Each page has 5
columns (A: Item Code; B: Date; C: Quantity; D: Unit Cost: E: Total Cost).
Each day, I download new sales data from the web. I have a macro that takes
the new sales data and puts it on the appropriate stores page and the bottom
of the list.

Now I am trying to write a macro that will take the latest days sales from
each store, copy it to a new page and print that page. I am having trouble
with the line that selects the most recent days rows on the store page. Here
is the relevant code.

"sht" is the Store Number, which is the name of the individual worksheets

Sub PrintLatestDay(sht As String)
Dim LastRow As Single
Dim StartRow As Single
Dim i As Single, j As Single
Dim InsertRow As Single
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False

'determines start and end of last day of sales on "sht"
LastRow = ThisWorkbook.Worksheets(sht).Cells(Rows.Count, 1).End(xlUp).Row
Worksheets(sht).Activate
For j = LastRow To 1 Step -1
If Not Cells(j, 2) = Cells(j - 1, 2) Then
StartRow = j
Exit For
End If
Next j

'copy template to "Sheet4". Sheet4 will be printed, then contents cleared
to make
'it ready for the next days execution of the macro. The template consists
of two
'title rows for each store separated by two blank rows. The data will be
inserted
'after the two title rows for each store.

ThisWorkbook.Worksheets("Sheet5").Cells.Copy
ThisWorkbook.Worksheets("Sheet4").Activate
Cells(1, 1).Select
ActiveSheet.Paste

'FindStore returns the row number of the first title row for a store, so I
know where
'to insert the copied data
InsertRow = FindStore(sht)

ThisWorkbook.Worksheets(sht).Range(Cells(StartRow, 1), Cells(LastRow,
5)).Select
Selection.Copy

'more code for pasting/printing etc.
End Sub

The second to last line above is where I get runtime error 1004 -
Application defined or Object defined error. The help file is not helpful,
at least not to my small brain.

I use a very similar line in the macro used to copy the downloaded data onto
the store pages in the first place. The only difference is that I have
"Cells(1,1)" instead of "Cells(FirstRow,1)". I don't know why that would
make a difference.

Any ideas?
TIA
Marcotte

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run-time error '50290': Application-defined or object-defined erro Macro button Excel Discussion (Misc queries) 1 March 12th 09 10:59 AM
Macro Run-time Error 1004 Application Defined or Object Defined Error Anddmx Excel Programming 6 June 9th 04 03:40 PM
Application-defined or object-defined error Sharon[_5_] Excel Programming 2 October 24th 03 03:49 PM
Runtime Error 1004 -- Application Defined or Object Defined Error John[_51_] Excel Programming 3 September 4th 03 04:28 PM
VBA - Application-defined or object-defined error Chip Pearson Excel Programming 0 August 24th 03 08:43 PM


All times are GMT +1. The time now is 02:29 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"