+ Reply to Thread
Results 1 to 6 of 6

VBA Clear Contents ONLY

  1. #1
    Forum Contributor
    Join Date
    12-06-2021
    Location
    Fort Lauderdale, Florida. United States
    MS-Off Ver
    365
    Posts
    143

    VBA Clear Contents ONLY

    Hello!

    I have a sheet in a workbook called "Backend_Data"

    The data to be scrutinized begins in Row # 7, Column A. (see attached workbook)

    • I need a VBA Code that will find all 0 in range("A7:A42") and if it finds a zero there, then clear.contents of that row up to Column E.


    PS: Deleting the row is not an option.

    This is only a sample file that i have attached. The real file is approximately 400K rows down, and 80 columns wide.

    Would someone be kind enough to help?

    Thank you!!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: VBA Clear Contents ONLY

    maybe something like this

    Please Login or Register  to view this content.
    Last edited by maniacb; 02-11-2022 at 02:10 PM.

  3. #3
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,408

    Re: VBA Clear Contents ONLY

    Does this do what you want...
    Please Login or Register  to view this content.
    Note: This code assumes there will be at least one cell in Column A of your data with a 0 in it. If that might not be the case, then you will have to add an On Error trap as SpecialCells will error out if it cannot find what it is looking for.
    Last edited by Rick Rothstein; 02-11-2022 at 02:16 PM.

  4. #4
    Forum Contributor
    Join Date
    12-06-2021
    Location
    Fort Lauderdale, Florida. United States
    MS-Off Ver
    365
    Posts
    143

    Re: VBA Clear Contents ONLY

    To Rick and Maniacb

    Thanks guys! both worked like a charm!

    There will never be a danger of no zeroes in column A. I have a macro that pulls in data from another sheet with 40K rows, and over 90% of them will always be 0


    Quick question to Rick: Your code worked perfectly but how did it know to sort the data afterwards? The zeroes were not consecutive at the bottom.


    Thank you!!!!
    Last edited by rob1963manwork; 02-11-2022 at 03:01 PM.

  5. #5
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,408

    Re: VBA Clear Contents ONLY

    Quote Originally Posted by rob1963manwork View Post
    Quick question to Rick: Your code worked perfectly but how did it know to sort the data afterwards? The zeroes were not consecutive at the bottom.
    I don't understand your question. My code is not sorting anything. All it does is mark all of the cells with 0 as #N/A and then the SpecialCells function locates all of those #N/A cells, uses the Intersect function to extend those located cells by five columns and then does a ClearContents on all of those cells. That's it... it does nothing else.

  6. #6
    Forum Contributor
    Join Date
    12-06-2021
    Location
    Fort Lauderdale, Florida. United States
    MS-Off Ver
    365
    Posts
    143

    Re: VBA Clear Contents ONLY

    Hi Rick..

    It's working properly but here is my question more detailed.

    My Data on the sheet [prior to running the code] goes like this:

    On Column A before code

    123
    0
    0
    123
    0

    After code

    123
    123

    Shouldn't it have left Blank Rows in between? Instead it looks as though I had sorted it. Which is fine, because i was planning to add a macro element to have leave all blank rows at the bottom but I didn't have to.

+ 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] Clear Contents depending on cell contents
    By terratushi in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-15-2017, 08:02 PM
  2. Clear merged cell contents in comand button(clear all)
    By mohan_984 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-25-2015, 10:39 AM
  3. clear contents of entire sheet except the contents of the table
    By wayneg in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-06-2015, 08:41 AM
  4. Clear Contents of a cell if contents = 1/0/00
    By superiorsvc in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-03-2015, 06:25 PM
  5. [SOLVED] Clear contents based on contents of another cell
    By Katrina DTE in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-13-2013, 02:44 PM
  6. Copy list contents down, then clear contents
    By hektisk in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-07-2011, 04:34 PM
  7. Clear sheet contents but retain Clipboard contents
    By nebb in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-25-2007, 01:42 PM

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