+ Reply to Thread
Results 1 to 9 of 9

Macro To Completely Delete Contents Of A Cell Range Based On Specific Text In The Cell

  1. #1
    Registered User
    Join Date
    02-06-2018
    Location
    Dublin, Ireland
    MS-Off Ver
    Microsoft Office 365 Home Subscription
    Posts
    47

    Macro To Completely Delete Contents Of A Cell Range Based On Specific Text In The Cell

    Hi All,

    I have a worksheet where I would like to completely delete the contents of cells based on the text in the cell leaving the cells where the condition is met, completely empty after the macro has run.

    The cell range is and always will be C11:AFT661

    Every cell in the range contains a formula

    The formula in each cell returns data from another workbook as TEXT or if no data is found leaves the cell blank.

    Where the TEXT returned into the cell by its formula begins with a 0 (that's a zero) the new macro should delete all contents in that cell including its formula leaving the cell completely empty.

    Thank you for reading and for any help forthcoming.

  2. #2
    Registered User
    Join Date
    03-25-2013
    Location
    Srinagar, JK, India
    MS-Off Ver
    Microsoft 365, Office 2007, 2010 & 2016
    Posts
    23

    Re: Macro To Completely Delete Contents Of A Cell Range Based On Specific Text In The Cell

    Try the below code


    Please Login or Register  to view this content.
    where cl represents each cell within your range.

    Note: This code will delete the contents and formatting of the specific cell beginning with 0 (zero), not the entire cell range.
    With regards,
    Mullah Raheil.

  3. #3
    Registered User
    Join Date
    02-06-2018
    Location
    Dublin, Ireland
    MS-Off Ver
    Microsoft Office 365 Home Subscription
    Posts
    47

    Re: Macro To Completely Delete Contents Of A Cell Range Based On Specific Text In The Cell

    Thank you mullahraheil, that works but can you alter it to leave the formatting as it is and to only delete the data/formula. Many Thanks.

  4. #4
    Registered User
    Join Date
    03-25-2013
    Location
    Srinagar, JK, India
    MS-Off Ver
    Microsoft 365, Office 2007, 2010 & 2016
    Posts
    23

    Re: Macro To Completely Delete Contents Of A Cell Range Based On Specific Text In The Cell

    Hi,

    Use cl.ClearContents instead of cl.Clear. That would delete the contents of the cell leaving the formatting as it is.

  5. #5
    Registered User
    Join Date
    02-06-2018
    Location
    Dublin, Ireland
    MS-Off Ver
    Microsoft Office 365 Home Subscription
    Posts
    47

    Re: Macro To Completely Delete Contents Of A Cell Range Based On Specific Text In The Cell

    Thank you ever so much mullahraheil,

  6. #6
    Registered User
    Join Date
    02-06-2018
    Location
    Dublin, Ireland
    MS-Off Ver
    Microsoft Office 365 Home Subscription
    Posts
    47

    Re: Macro To Completely Delete Contents Of A Cell Range Based On Specific Text In The Cell

    My initial problem was solved, but now I would like to include something extra into the code provided to me.

    Can somebody amend the code so that it will also clear out the formula in a cell where it has returned no data and left the cell blank.

    For Each cl in Range("C11:AFT661")
    If Left(cl.value,1) = 0 Then cl.ClearContents
    Next cl

    AboveIs the code that solved my initial problem, I have duplicated it to below

    For Each cl in Range("C11:AFT661")
    If Left(cl.value,1) = " " Then cl.ClearContents
    Next cl

    But rathar than run 2 seperate macros, how do I express 0 or " " into the one macro

    Thanks.

  7. #7
    Registered User
    Join Date
    02-06-2018
    Location
    Dublin, Ireland
    MS-Off Ver
    Microsoft Office 365 Home Subscription
    Posts
    47

    Re: Macro To Completely Delete Contents Of A Cell Range Based On Specific Text In The Cell

    Can anybody help please?

  8. #8
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,480

    Re: Macro To Completely Delete Contents Of A Cell Range Based On Specific Text In The Cell

    I think it would be,

    Please Login or Register  to view this content.
    You should use code tags when showing code, it is the 2nd rule of this forum.

  9. #9
    Registered User
    Join Date
    02-06-2018
    Location
    Dublin, Ireland
    MS-Off Ver
    Microsoft Office 365 Home Subscription
    Posts
    47

    Re: Macro To Completely Delete Contents Of A Cell Range Based On Specific Text In The Cell

    davesexcel, thank you ever so much for your solution, it really is greatly appreciated, thanks again, Mike.

+ 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. VBA MAcro to clear contents of specific cells if a specific cell contains text
    By muzzareilly in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-28-2017, 12:47 PM
  2. [SOLVED] Delete contents of a cell in a given range if it matches contents of a specific cell
    By rcicconetti in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-13-2016, 06:46 AM
  3. [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
  4. Macro to delete several rows based on a cell's contents
    By ppp112 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-26-2013, 01:16 PM
  5. [SOLVED] Return contents of a cell that contains a specific text within a range.
    By nhi in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-04-2013, 07:54 PM
  6. Macro that will clear contents of cell based on format of text in adjacent cell
    By judasdac in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-12-2012, 01:56 AM
  7. Macro to delete entire row based on cell contents
    By ATX in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 10-06-2011, 03:52 AM

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