+ Reply to Thread
Results 1 to 8 of 8

Delete rows when two columns are empty

  1. #1
    Registered User
    Join Date
    04-28-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    3

    Delete rows when two columns are empty

    Hi folks, new to the Forum.

    I have hit a problem that I can't seem to find a solution for online and was hoping someone could help.

    I have used a piece of code elsewhere in the macro I am writing that finds empty cells in Column D and deletes the row where it finds them.

    Please Login or Register  to view this content.
    ("Last" is a wonderful custom function I found a long time ago that finds the final row or column of used data in a number of formats)

    My problem is, I have come across an instance on a worksheet where the row should only be deleted if both Column C and Column D are empty. There are multiple instances of one having a value in it but not the other, and I want those rows left alone.

    I tried altering part of the code to:

    Please Login or Register  to view this content.
    But this would delete the row if either column was empty, even if there was a value in the other one.

    And when I tried:

    Please Login or Register  to view this content.
    Excel got angry at me!

    I'd prefer not to use a loop if possible, but have no worries about doing so if need be.

    Hoping someone can help
    Last edited by Musoguy; 04-29-2013 at 01:52 AM.

  2. #2
    Forum Contributor
    Join Date
    01-02-2007
    Location
    Australia NSW
    MS-Off Ver
    2013
    Posts
    494

    Re: Delete rows when two columns are empty

    Something like:
    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Delete rows when two columns are empty

    Musoguy,

    Welcome to the Excel Forum.

    To get the most precise answer, it is best to upload/attach a sample workbook (sensitive data scrubbed/removed/changed) that contains an example of your raw data on one worksheet, and on another worksheet your desired results.

    The structure and data types of the sample workbook must exactly duplicate the real workbook. Include a clear and explicit explanation of your requirements.

    To attach your workbook, scroll down and click on the Go Advanced button, then scroll down and click on the Manage Attachments button.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  4. #4
    Registered User
    Join Date
    04-28-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Delete rows when two columns are empty

    Coreytroy thank you for your reply, unfortunately your code returns an error.

    Thanks Stan, example workbook is attached
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Delete rows when two columns are empty

    Hi Musoguy,

    Welcome to the forum!!

    Try this (initially on a copy of your data as the results cannot be undone if they're not as expected):

    Please Login or Register  to view this content.
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  6. #6
    Registered User
    Join Date
    04-28-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Delete rows when two columns are empty

    Thank you so much Robert, exactly what I was hoping for

    James

  7. #7
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Delete rows when two columns are empty

    Thanks for letting us know, James. I'm glad we were able to get it sorted for you

    Robert

  8. #8
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Delete rows when two columns are empty

    Musoguy,

    Sorry for the delay.

    With your raw data in Sheets(1).

    The below macro produced the results you are looking for in Sheets(1) with a runtime of 0.000 seconds because of the use of arrays in memory.

    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    Please Login or Register  to view this content.
    Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

    Then run the ReorgData macro.

+ 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