+ Reply to Thread
Results 1 to 9 of 9

Clear All Sheets Except First/Specific Name

  1. #1
    Forum Contributor
    Join Date
    05-27-2012
    Location
    New Brunswick, Canada
    MS-Off Ver
    Excel 2016
    Posts
    327

    Clear All Sheets Except First/Specific Name

    I have the following code and I want to perform some things to every sheet after the first. And the first is called MU. It seems to be clearing ONLY the MU, which is basically the opposite of what I want.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Clear All Sheets Except First/Specific Name

    This is not efficient code, but it should do ( I have not tested it).
    Probably do not need this line

    .Columns("A:I").Select
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    05-27-2012
    Location
    New Brunswick, Canada
    MS-Off Ver
    Excel 2016
    Posts
    327

    Re: Clear All Sheets Except First/Specific Name

    That worked but I now can't make it work with the existing (altbeit much more complicated) code. Any ideas? Again it does the exact opposite, running on the MU tab instead of all other tabs after it

    Please Login or Register  to view this content.
    This is how I tried to modify it
    Please Login or Register  to view this content.
    Last edited by Wheelie686; 06-11-2016 at 11:01 AM.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Clear All Sheets Except First/Specific Name

    You need to use a "DOT" with With.
    I have adjusted most of the lines, but not all of them as you have a call code.

    Please Login or Register  to view this content.
    Last edited by AB33; 06-11-2016 at 11:36 AM.

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Clear All Sheets Except First/Specific Name

    Try this (not tested).

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Clear All Sheets Except First/Specific Name

    Please Login or Register  to view this content.
    All these lines can be shortened to
    Please Login or Register  to view this content.
    Last edited by AB33; 06-11-2016 at 12:38 PM.

  7. #7
    Forum Contributor
    Join Date
    05-27-2012
    Location
    New Brunswick, Canada
    MS-Off Ver
    Excel 2016
    Posts
    327

    Re: Clear All Sheets Except First/Specific Name

    Both codes and my original attempt seem to highlight the same line of code. I did test what AlphaFrog gave me and it seems to have run the macro but only for sheet 2. It seems to have attempted it on Sheet 3 but stopped when it ran into that line.

    Please Login or Register  to view this content.
    Thank you AB33 for the Array code. I hadn't thought of doing it that way to make it cleaner
    Last edited by Wheelie686; 06-11-2016 at 02:08 PM.

  8. #8
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Clear All Sheets Except First/Specific Name

    You should include the error description as that could provide diagnostic info.

    Need to reset rngDelRange for each worksheet otherwise it's trying to union ranges from different sheets and that throws an error.

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    05-27-2012
    Location
    New Brunswick, Canada
    MS-Off Ver
    Excel 2016
    Posts
    327

    Re: Clear All Sheets Except First/Specific Name

    Thank you! I've been teaching myself VBA over the last little while and it's hard to know how to get around a problem until you end up finding out the hard way. Much appreciated AlphaFrog and AB33.

+ 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] If a specific row contains a word, then clear specific content in corresponding column.
    By johansoder in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-18-2014, 05:38 PM
  2. macro to clear a range in specific sheets
    By indiana115 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-27-2014, 07:53 PM
  3. [SOLVED] Clear contents of specific cells on the same row if a specific cell on that row is empty
    By djfscouse in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-28-2014, 01:48 PM
  4. [SOLVED] How to clear specific combo box in Userform
    By Bflare in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-26-2014, 12:28 PM
  5. [SOLVED] Looping through sheets to clear a specified range, but excluding some sheets
    By d.sanchez in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-03-2013, 02:39 PM
  6. [SOLVED] Clear specific cells
    By ecelaras in forum Excel General
    Replies: 5
    Last Post: 03-10-2013, 05:06 PM
  7. Code to clear contents of specific cells based upon if key exists in other sheets
    By seputus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-31-2013, 07:25 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