Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Error when deleting rows
What i do is, I merge about 100 xls files into one master xls file.
But some records have empty rows that have to be deleted or they mess up the formating. So i wrote some code but theres an issue. Heres a part of the code: Set mybook = Workbooks.Open(FNames) 'mybook.DisplayAlerts = False lrow = LastRow(mybook.Sheets(1)) ActiveSheet.Range("C8:C" & lrow).SpecialCells(xlCellTypeBlanks).EntireRow.Del ete Set sourceRange = mybook.Worksheets(1).Range("A1:IV" & lrow) rnum = 1 SourceRcount = sourceRange.Rows.Count Set destrange = basebook.Worksheets(1).Cells(rnum, "A") sourceRange.Copy destrange This does the job, it deletes the rows... BUT, when it comes to an XLS file without any empty/blank rows, it generates an Error and stops working. How would i make it do a check to see if theres actually blank rows to begin with??? thanks in advance |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Error when deleting rows
Hi W,
Try replacing: ActiveSheet.Range("C8:C" & lrow).SpecialCells(xlCellTypeBlanks).EntireRow.Del ete with On Error Resume Next ActiveSheet.Range("C8:C" & LRow). _ SpecialCells(xlCellTypeBlanks).EntireRow.Delete On Error GoTo 0 Incidentally, although you have commnted the line: 'mybook.DisplayAlerts = False If used, it should read: Application.DisplayAlerts = False --- Regards, Norman "wmureports" wrote in message ps.com... What i do is, I merge about 100 xls files into one master xls file. But some records have empty rows that have to be deleted or they mess up the formating. So i wrote some code but theres an issue. Heres a part of the code: Set mybook = Workbooks.Open(FNames) 'mybook.DisplayAlerts = False lrow = LastRow(mybook.Sheets(1)) ActiveSheet.Range("C8:C" & lrow).SpecialCells(xlCellTypeBlanks).EntireRow.Del ete Set sourceRange = mybook.Worksheets(1).Range("A1:IV" & lrow) rnum = 1 SourceRcount = sourceRange.Rows.Count Set destrange = basebook.Worksheets(1).Cells(rnum, "A") sourceRange.Copy destrange This does the job, it deletes the rows... BUT, when it comes to an XLS file without any empty/blank rows, it generates an Error and stops working. How would i make it do a check to see if theres actually blank rows to begin with??? thanks in advance |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Deleting a range of rows based on a variable; syntax error | Excel Discussion (Misc queries) | |||
Macro for deleting rows and serialising the remaing rows | Setting up and Configuration of Excel | |||
Code deleting all rows in error | Excel Programming | |||
Help!! I have problem deleting 2500 rows of filtered rows!!!! | Excel Discussion (Misc queries) | |||
Deleting rows based upon Error conditions | Excel Programming |