+ Reply to Thread
Results 1 to 2 of 2

Error when deleting rows

  1. #1
    wmureports
    Guest

    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.Delete
    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. #2
    Norman Jones
    Guest

    Re: Error when deleting rows

    Hi W,

    Try replacing:

    > ActiveSheet.Range("C8:C" &
    > lrow).SpecialCells(xlCellTypeBlanks).EntireRow.Delete


    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" <[email protected]> wrote in message
    news:[email protected]...
    > 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.Delete
    > 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1