Home |
Search |
Today's Posts |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thank you Joel.
'There are two last rows LastRow = .Cells(Rows.Count, "A").End(xlUp).Row 'LastRow = ActiveCell.SpecialCells(xlCellTypeLastCell).Row LastCol = .Cells(1, Columns.Count).End(xlToLeft).Column 'Not sure what this is doing? 'Sheets.Item(A1).Select I was trying to determine what sheet the procedure was operating on and I neglected to remove the test. Since you added the "With" clause, the procedure is working. Thanks for your attention and help. Dan On Sep 27, 5:49 pm, Joel wrote: I started using the with statement to make sure I'm on the correct sheet and avoid using the select method unless absolutely necessary. Some methods only work with select. The set MyRange statement would fail if LastRow or LastCol were not valid. Private Sub cmdComplete_Click() Dim MyRange As Range Dim LastRow As Long Dim LastCol As Long with Sheets("CompleteQuote") 'There are two last rows LastRow = .Cells(Rows.Count, "A").End(xlUp).Row 'LastRow = ActiveCell.SpecialCells(xlCellTypeLastCell).Row LastCol = .Cells(1, Columns.Count).End(xlToLeft).Column 'Not sure what this is doing? 'Sheets.Item(A1).Select Set MyRange = .Range("A19", .Cells(LastRow, LastCol)) 'LastRow.Select 'MyRange.Select DoTheExport Clear_Unlocked2 .Range("A19:G65536").ClearContents txtCount = 0 end with Sheets("QuotedPart").Activate End Sub Hi Joel, I've been debugging using F8. To get the yellow highlight to move through the code, I had to dim MyRange, LastRow and LastCol. I'm not sure how they should be dimensioned. . .So I chose as Range for MyRange, as Long for LastRow and LastCol. Anyway these variables show the last row is 87. I deleted blank rows below my data and closed the workbook--it still shows last row as 87. When I look at the spreadsheet it looks like the last row is 68. I suspect MyRange, LastRow and Last Column are calculating on a sheet other than my intended sheet. I don't know how to determine where the procedure is getting the values. MyRange returns an error--"Run-time error '1004': Application-defined or object-defined error" I suspect this is because I am running a private procedure from a button on the sheet, QuotedPart, that is manipulating a different sheet, CompletedQuote. Do you have any further feedback? Thanks, Dan Private Sub cmdComplete_Click() Dim MyRange As Range Dim LastRow As Long Dim LastCol As Long Sheets("CompleteQuote").Activate Sheets.Item(A1).Select LastRow = Cells(Rows.Count, "A").End(xlUp).Row LastCol = Cells(1, Columns.Count).End(xlToLeft).Column LastRow = ActiveCell.SpecialCells(xlCellTypeLastCell).Row Set MyRange = Range("A19", Cells(LastRow, LastCol)) 'LastRow.Select 'MyRange.Select DoTheExport Clear_Unlocked2 Worksheets("CompleteQuote").Range("A19:G65536").Cl earContents txtCount = 0 Sheets("QuotedPart").Activate End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Chip Pearson's NewWorkDays formula | Excel Discussion (Misc queries) | |||
DeleteDuplicatesViaFilter From Chip Pearson's Website | Excel Programming | |||
How to Use Chip Pearson's Text Import Code | Excel Programming | |||
Chip Pearson's Forum Etiquette | New Users to Excel | |||
Help with Chip Pearson's Code for Deleting Blank Rows | Excel Programming |