+ Reply to Thread
Results 1 to 19 of 19

Delete Range if cell in range is blank

  1. #1
    Registered User
    Join Date
    09-02-2011
    Location
    Bulgaria
    MS-Off Ver
    2013
    Posts
    91

    Question Delete Range if cell in range is blank

    Hi All,

    i searched many posts but all of them seem to be for different cases.
    i have sheet where i am pasting raw data table from column BA to CA

    my data has random blank cells in column BY
    i want to make macro to delete the range BA##:CA## where BY cell is blank

    (i dont want to delete the whole row because i have other data in the rest of the columns A:AZ)
    tried many examples but cant seem to be able to find proper way to delete only the range

    can you help me on this?
    Attached Files Attached Files
    Last edited by godlev; 03-12-2018 at 01:05 PM.
    Truth fears no questions.

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Delete Range if cell in range is blank

    [QUOTE]i want to make macro to delete the range BA##:CA## where BY cell is blank
    Please Login or Register  to view this content.
    Last edited by kev_; 03-12-2018 at 01:40 PM. Reason: ClearContents was mistyped!
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Registered User
    Join Date
    09-02-2011
    Location
    Bulgaria
    MS-Off Ver
    2013
    Posts
    91

    Re: Delete Range if cell in range is blank

    i run the script but i get error message

    Run-Time error '438':

    Object doesn't support this property or method

    debug.PNG

  4. #4
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Delete Range if cell in range is blank

    Note my edit
    I mistyped ClearContents

  5. #5
    Registered User
    Join Date
    09-02-2011
    Location
    Bulgaria
    MS-Off Ver
    2013
    Posts
    91

    Re: Delete Range if cell in range is blank

    it is deleting the content of the range but it is not shifting the rows up
    maybe i couldn't express that i want to delete the cells in range BA:CA where BY is empty and then the shift the rest of the cells up

    so if BY3 cell is empty the BA3:BY3 range to be deleted and the cells below to be shifted so there is no blank row left over

  6. #6
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Delete Range if cell in range is blank

    I am away from PC right now - so cannot test
    - we may need to do this starting with last row - will test later
    Last edited by kev_; 03-13-2018 at 02:00 AM.

  7. #7
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Delete Range if cell in range is blank

    Here you go:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    09-02-2011
    Location
    Bulgaria
    MS-Off Ver
    2013
    Posts
    91

    Re: Delete Range if cell in range is blank

    Worked like charm - Thank You!!!

  9. #9
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Delete Range if cell in range is blank

    Thanks for marking thread SOLVED and for the rep

  10. #10
    Registered User
    Join Date
    09-02-2011
    Location
    Bulgaria
    MS-Off Ver
    2013
    Posts
    91

    Re: Delete Range if cell in range is blank

    Kev one last request - if i want to change the column range lets say range is A to Z and blank cells in C will determine deletion - i tried to modify it but coulnt figure out how to adjust the numbers

    Please Login or Register  to view this content.

  11. #11
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Delete Range if cell in range is blank

    Column C offset -1 column is B , etc


    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    09-02-2011
    Location
    Bulgaria
    MS-Off Ver
    2013
    Posts
    91

    Re: Delete Range if cell in range is blank

    Hi Kev - thanks for assisting me so far but it seems my raw data is having blank cells which are not really blank
    attached a new example which i copied from the raw data and replaced the content with XXXXX
    if you can see the cell C3 is completely blank and the B3 is displayed over it
    The rest of the cells in C column seems to be blank but they are not really and the VBA is not detecting them as blank
    Attached Files Attached Files

  13. #13
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Delete Range if cell in range is blank

    I am away from PC for several days now and so cannot download your workbook.Limited to what I can manage via phone.
    What does "not blank" mean? Do they contain an empty string or a formula resulting in empty string? Or something else?

  14. #14
    Registered User
    Join Date
    09-02-2011
    Location
    Bulgaria
    MS-Off Ver
    2013
    Posts
    91

    Re: Delete Range if cell in range is blank

    i made a screenshot if it will help
    when i select C2 which looks like empty but script does not detect it as empty
    inside there is no nothing even single space

    i guess somehow it is containing empty string as you said
    if i double click the cell and then press enter without changing anything - then it becomes empty and the content of B2 is displayed over it (this is the usual behavior when excel cell string is wider then the width of the column)

    Capture2.PNG

  15. #15
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Delete Range if cell in range is blank

    If cells not blank then SpecialCells method will not work
    Looking at your picture some of the cells appear to be empty but others may not be.

    Why use column C to determine last row?which column (A - Z) is most likely to contain a value in last row (unlikely to be C if using blanks in that to clear the others)
    Try amending the column determining last row and see if that works (which it will if the cells are genuinely empty)

  16. #16
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Delete Range if cell in range is blank

    If cells not blank then SpecialCells method will not work
    Looking at your picture some of the cells appear to be empty but others may not be.

    Why use column C to determine last row?which column (A - Z) is most likely to contain a value in last row (unlikely to be C if using blanks in that to clear the others)
    Try amending the column determining last row and see if that works (which it will if the cells are genuinely empty)

  17. #17
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Delete Range if cell in range is blank

    Busy for several hours now. Will check thread then.

  18. #18
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Delete Range if cell in range is blank

    Did you try what I suggested?

  19. #19
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Delete Range if cell in range is blank

    Possibly?
    Please Login or Register  to view this content.
    Last edited by kev_; 03-14-2018 at 05:14 AM.

+ 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. [SOLVED] Find first blank cell in first column of known range, select and delete from that point
    By johnstevens in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-09-2014, 09:41 AM
  2. [SOLVED] Macro Delete Contents in 23rd corresponding cell if the cell in range is a non-blank cell
    By murtaza.khan in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-04-2014, 01:11 AM
  3. Code look through range of cells, find blanks & delete cell range in the same row,
    By EagleInsight in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-10-2014, 11:24 AM
  4. Replies: 1
    Last Post: 09-04-2013, 07:23 AM
  5. [SOLVED] Copy data from a range of cells into a blank range based on common cell
    By vanmeterkj in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-03-2012, 10:18 AM
  6. Delete Blank Rows-Blank Row between my data range
    By Bob@Sun in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-27-2010, 02:52 PM
  7. Delete a range of rows above blank cell
    By d_rock90 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-07-2008, 10:45 PM

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