+ Reply to Thread
Results 1 to 3 of 3

conditional task in Excel 2003 macro

  1. #1
    Joseph Spain
    Guest

    conditional task in Excel 2003 macro

    Good morning,

    I ran into a problem yesterday with a macro I have used for a few months
    without incident. I am receiving the following run-time error:

    ----------------

    Run-time error '1004':

    No cells were found.

    ----------------

    My macro is supposed to look for blank cells in a given range, find them,
    and deletes the entire row(s) found to contain the blank cells. The error
    is now occuring because, for the first time, no blank cells exist, and I
    failed to consider this possibility.

    Here is the part of macro that fails when no blank cells are found.

    -----------------

    'delete rows with blank cells

    Columns("A:A").Select
    Selection.SpecialCells(xlCellTypeBlanks).Select
    Selection.EntireRow.Delete

    -----------------

    How can I cope with cases where no blank cells in a given range exist and
    then simply bypass this part of the macro? A conditional statement, I
    assume. Any thoughts?

    As always, thanks much for any help offered.

    Best Regards,
    Joseph



  2. #2
    Patrick Molloy
    Guest

    Re: conditional task in Excel 2003 macro

    one simple way

    On Error resume Next
    Columns("A:A").SpecialCells(xlCellTypeBlanks).Select
    If Err.Number = 0 Then
    Selection.EntireRow.Delete
    End If

    "Joseph Spain" <icystorm-removethis-@-removethisnospam-hotmail.com> wrote in
    message news:P5vae.402$Bb.97@okepread06...
    > Good morning,
    >
    > I ran into a problem yesterday with a macro I have used for a few months
    > without incident. I am receiving the following run-time error:
    >
    > ----------------
    >
    > Run-time error '1004':
    >
    > No cells were found.
    >
    > ----------------
    >
    > My macro is supposed to look for blank cells in a given range, find them,
    > and deletes the entire row(s) found to contain the blank cells. The error
    > is now occuring because, for the first time, no blank cells exist, and I
    > failed to consider this possibility.
    >
    > Here is the part of macro that fails when no blank cells are found.
    >
    > -----------------
    >
    > 'delete rows with blank cells
    >
    > Columns("A:A").Select
    > Selection.SpecialCells(xlCellTypeBlanks).Select
    > Selection.EntireRow.Delete
    >
    > -----------------
    >
    > How can I cope with cases where no blank cells in a given range exist and
    > then simply bypass this part of the macro? A conditional statement, I
    > assume. Any thoughts?
    >
    > As always, thanks much for any help offered.
    >
    > Best Regards,
    > Joseph
    >




  3. #3
    Joseph Spain
    Guest

    Re: conditional task in Excel 2003 macro

    "Patrick Molloy" <patrick_molloy@hotmail.com> wrote:

    > one simple way
    >
    > On Error resume Next
    > Columns("A:A").SpecialCells(xlCellTypeBlanks).Select
    > If Err.Number = 0 Then
    > Selection.EntireRow.Delete
    > End If


    Thanks much, Patrick. That works perfectly.

    Best regards,
    Joseph



+ 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