Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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
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
Deleting a range of rows based on a variable; syntax error Babymech Excel Discussion (Misc queries) 3 January 16th 09 06:19 PM
Macro for deleting rows and serialising the remaing rows Srinivasulu Bhattaram Setting up and Configuration of Excel 1 November 12th 08 06:05 PM
Code deleting all rows in error JOUIOUI Excel Programming 3 June 10th 06 08:39 PM
Help!! I have problem deleting 2500 rows of filtered rows!!!! shirley_kee Excel Discussion (Misc queries) 1 January 12th 06 03:24 AM
Deleting rows based upon Error conditions JEff Excel Programming 1 December 28th 04 09:55 PM


All times are GMT +1. The time now is 08:00 AM.

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"