+ Reply to Thread
Results 1 to 8 of 8

Remove rows with empty cells in column 1

  1. #1
    Registered User
    Join Date
    08-16-2012
    Location
    connecticut
    MS-Off Ver
    Excel 2007
    Posts
    14

    Remove rows with empty cells in column 1

    Hi All, I'm new to VBA and trying to write a macro that will delete all the rows that contain a blank cell in column 1 (A), I'm attaching an example of my spreadsheet and the macro I've come up with so far. The problem is that the macro loops continuously and the only way I can stop it is to end the application which obviously loses the data.

    Any help is greatly appreciated


    Thanks, dave
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Remove rows with empty cells in column 1

    Try something like this...

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Remove rows with empty cells in column 1

    Because this line is not going be true

    Please Login or Register  to view this content.
    May be

    Please Login or Register  to view this content.
    Assuming you are dealing (selecting) with column "A".

  4. #4
    Registered User
    Join Date
    08-16-2012
    Location
    connecticut
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Remove rows with empty cells in column 1

    You my friend are The Man
    I just tried it and it works PERFECTLY

    Many Thanks,
    dave

  5. #5
    Registered User
    Join Date
    08-16-2012
    Location
    connecticut
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Remove rows with empty cells in column 1

    Hi AB33, I tried pasting your code into my original macro (deleting my "Do Until" statement) but received a Object doesn't support this property or method error as soon as it hit the new line. But I do appreciate your trying.

    Thanks,
    dave

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Remove rows with empty cells in column 1

    No, your code will not work. If you just want to delete empty columns in A, you can not say until that column is blank.
    Instead, you can use either of these codes. The first code just simple deletes the row if it finds empty cell in column A, while the second one is the same but it stops when column A finds Ref. No-That is where the codes stops and would not look for empty column A

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by AB33; 11-06-2012 at 07:13 PM.

  7. #7
    Registered User
    Join Date
    08-16-2012
    Location
    connecticut
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Remove rows with empty cells in column 1

    Hi AB33, I tried both your codes, the first worked fine but the second went into an endless loop.

    Still, thanks for your efforts.

    dave

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Remove rows with empty cells in column 1

    Because of this line

    Do Until Cells(i, 1).Value = "Ref. No."

    to test it put "Ref. No." in any column "A".
    If you do not have a cell with "Ref. No." in column A, it is going to loop indefinitely. My assumption of what were trying to do was to loop throught column A until it find "Ref. No.". Until this point, the code will look for a blank in column A, if it finds it, it delete it.
    However, loop until column A is blank while trying to find a blank cell in column A will not work and would not make any sense either.
    I hope this make sense

+ 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