Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Run-time error '50290': Application-defined or object-defined erro | Excel Discussion (Misc queries) | |||
Macro Run-time Error 1004 Application Defined or Object Defined Error | Excel Programming | |||
Application-defined or object-defined error | Excel Programming | |||
Runtime Error 1004 -- Application Defined or Object Defined Error | Excel Programming | |||
VBA - Application-defined or object-defined error | Excel Programming |