+ Reply to Thread
Results 1 to 11 of 11

VBA to Clear Contents of Filtered Range

  1. #1
    Registered User
    Join Date
    05-22-2021
    Location
    US
    MS-Off Ver
    Excel 365
    Posts
    87

    VBA to Clear Contents of Filtered Range

    I have a file with data from data in column A thru column BQ with column A having data in each row and the number of rows vary. There are headers in the first row.

    Below is the macro I wrote but doesn't work as planned. It is suppose to filter column AC for "Constant". If any "Constant" appears, clear only the data in column AC that has "Constant". If no "Constant" appears, do nothing.

    I appreciate any help.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,479

    Re: VBA to Clear Contents of Filtered Range

    You're filtering for "Continuous" instead of "Constant" in the AutoFilter line — looks like a simple slip.

    You're using LastRow before assigning it a value, which might cause an error.

    You’re checking the number of visible cells but referencing LastRow again in that range, which could misalign if the filtered range is smaller.

    Here’s a refined version that directly checks for "Constant" in column AC and clears those visible cells if any are found:

    Please Login or Register  to view this content.

  3. #3
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,072

    Re: VBA to Clear Contents of Filtered Range

    A different approach...
    Please Login or Register  to view this content.
    OR

    Please Login or Register  to view this content.
    Last edited by Sintek; 06-26-2025 at 03:44 PM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  4. #4
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    873

    Re: VBA to Clear Contents of Filtered Range

    Or:
    Please Login or Register  to view this content.
    Or:
    Please Login or Register  to view this content.
    Harry.

  5. #5
    Registered User
    Join Date
    05-22-2021
    Location
    US
    MS-Off Ver
    Excel 365
    Posts
    87

    Re: VBA to Clear Contents of Filtered Range

    All of these worked. Thanks so much.

  6. #6
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,072

    Re: VBA to Clear Contents of Filtered Range

    ..........................
    Tx-Yoda.gif

  7. #7
    Registered User
    Join Date
    05-22-2021
    Location
    US
    MS-Off Ver
    Excel 365
    Posts
    87

    Re: VBA to Clear Contents of Filtered Range

    Sintek - I think when I added reputation, I clicked disapprove instead of approve in error but left very positive comments. I contacted the admin to see if someone could check if I clicked the wrong button and correct it if I did. My apologies if I did so. Your code worked perfectly. Your second option was in fact the one I went with! Thanks again for your help.

  8. #8
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,072

    Re: VBA to Clear Contents of Filtered Range

    Noticed that...All good though...Thanks...

  9. #9
    Valued Forum Contributor
    Join Date
    05-02-2013
    Location
    Poland
    MS-Off Ver
    Excel 2013
    Posts
    368

    Re: VBA to Clear Contents of Filtered Range

    Quote Originally Posted by ellenlewis View Post
    I think when I added reputation,
    By the way, I'm asking. What's with this reputation, that everyone is hunting for reputation? For me, since you wrote post #5, "Thank you" is enough. I won't get bread or wine for reputation. To give reputation without post #5 means, I understand, that one shouldn't litter the forum.
    Why both "Thank you" and reputation?

  10. #10
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,479

    Re: VBA to Clear Contents of Filtered Range

    Thank you. Best wishes in your endeavors.

  11. #11
    Registered User
    Join Date
    05-22-2021
    Location
    US
    MS-Off Ver
    Excel 365
    Posts
    87

    Re: VBA to Clear Contents of Filtered Range

    Honestly, I'm not sure. But whenever someone helps me and their code works, I always add reputation because I certainly appreciate your time and expertise. Perhaps with enough reputations, the bread and wine will come! If that is the case, I will continue to do my part in hopes of getting you some bread and wine!

    Thanks so much for your help!

+ 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. Clear Contents after a certain range
    By wherdzik in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-23-2020, 01:53 PM
  2. [SOLVED] Clear contents of every second row from filtered data
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-08-2017, 06:59 AM
  3. [SOLVED] Clear contents of range
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-25-2016, 01:15 PM
  4. [SOLVED] Clear contents for filtered range only
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-13-2016, 03:39 AM
  5. [SOLVED] If each cell in range equals 0 then clear contents of range and move to the next row
    By dagardner in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-19-2014, 08:44 PM
  6. [SOLVED] Clear Range Contents
    By kenadams378 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-23-2013, 07:06 AM
  7. [SOLVED] clear contents of range
    By KATIEexcel in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-14-2012, 08:11 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