+ Reply to Thread
Results 1 to 11 of 11

Code look through range of cells, find blanks & delete cell range in the same row,

  1. #1
    Registered User
    Join Date
    01-09-2014
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    15

    Thumbs up Code look through range of cells, find blanks & delete cell range in the same row,

    I am new to using vba and just understand the basics. THerefore would really appreciate your help.

    I have a list of data, such as the below, across 6 columns. I need a macro that will search through a named range of all columns, then identify if the cell is a blank and if so delete a range of cells in the same row (ie below cells a2 to f2).

    In the example below, the result of the macro should be to have only the last two rows remain as the others all have blanks.

    Thank you!

    X1 X2 X3 X4 X5
    Feb-07
    Mar-07 0.57%
    Apr-07 2.55%
    May-07 1.34%
    Jun-07 -5.88% -0.13%
    Jul-07 0.67% 4.44%
    Aug-07 0.01% 2.55% 5.73%
    Sep-07 0.89% 1.34% -0.21%
    Oct-07 3.24% -5.88% 1.45%
    Nov-07 -0.13% 0.67% 5.10%
    Dec-07 4.44% 5.73% 5.80%
    Jan-08 5.73% -0.21% 0.57%
    Feb-08 -0.21% -0.21% 2.55%
    Mar-08 1.27% 1.27% 1.34%
    Apr-08 -0.88% -0.88% -6.71%
    May-08 -0.75% -0.75% -0.25%
    Jun-08 5.66% 1.25% 1.25% 2.55% 1.00%
    Jul-08 3.22% 4.00% 4.00% -1.66% 2.00%
    Attached Files Attached Files
    Last edited by EagleInsight; 01-10-2014 at 10:47 AM.

  2. #2
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: Code look through range of cells, find blanks & delete cell range in the same row,

    Hi and welcome to the forum,
    There are many way to do it.... here's one.
    Looping through all rows from the end and delete if number of filled cells <> 6
    Please Login or Register  to view this content.
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

  3. #3
    Forum Contributor
    Join Date
    03-28-2013
    Location
    *
    MS-Off Ver
    Excel 2010
    Posts
    226

    Re: Code look through range of cells, find blanks & delete cell range in the same row,

    Please Login or Register  to view this content.
    Give Feedback and Click(*)

  4. #4
    Registered User
    Join Date
    01-09-2014
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Code look through range of cells, find blanks & delete cell range in the same row,

    Thank you GC Excel, much appreciated.

    As I am just learning the basic, would you be able to explain what each line represents?

  5. #5
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: Code look through range of cells, find blanks & delete cell range in the same row,

    Hi,
    I've added some comment to the code :
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    01-09-2014
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Code look through range of cells, find blanks & delete cell range in the same row,

    Utterly amazing. Thanks!

  7. #7
    Registered User
    Join Date
    01-09-2014
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Code look through range of cells, find blanks & delete cell range in the same row,

    Is there a way of extending the code to include a column that is completely blank but not delete all the rows given this.

    For instance, can it consider the top row cells A1 to G1 and for those columns that have titles to then analyse the data and delete any rows with blanks.

    Hopefully that makes sense, i've updated the spreadsheet at the top try show this.

    I tried to revise your code with as this, but it doesnt work:
    If Application.CountA(Cells(i, 1).Resize(1, 7)) <> CountA(Cells(i, 7)) Then
    Rows(i).EntireRow.Delete

    Thanks!

  8. #8
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: Code look through range of cells, find blanks & delete cell range in the same row,

    If I understand correctly, if C1 and E1 are empty then it should not be considered in the analysis?
    Will it always be the same columns or not ?

  9. #9
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: Code look through range of cells, find blanks & delete cell range in the same row,

    Will this work ?

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    01-09-2014
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Code look through range of cells, find blanks & delete cell range in the same row,

    In the example i tried to explain, it is if G1 (and therefore column G) is empty then dont consider it. However this is not static, and it may be that cells c1 to g1 may be empty.

  11. #11
    Registered User
    Join Date
    01-09-2014
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Code look through range of cells, find blanks & delete cell range in the same row,

    that does it perfectly!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 6
    Last Post: 03-04-2013, 06:34 PM
  2. Code to find named range doesn't find the correct field range?
    By matrixpom in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-12-2012, 05:54 PM
  3. Replies: 0
    Last Post: 10-04-2012, 08:21 PM
  4. Range Select + Delete Blanks
    By pr4t3ek in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-30-2008, 11:11 PM
  5. automate delete blanks in data range
    By mikesmith200550 in forum Excel General
    Replies: 1
    Last Post: 03-18-2006, 05:40 AM

Tags for this Thread

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