+ Reply to Thread
Results 1 to 9 of 9

Help needed for modifying code - clear contents

  1. #1
    Registered User
    Join Date
    05-09-2018
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    86

    Help needed for modifying code - clear contents

    Hi all,

    I have the following code to clear data in multiple sheets (altogether 78 sheets)

    Sub sbClearCellsOnlyData()
    Sheets("Activation (2)").Select
    Range("A21:L6000").ClearContents
    Sheets("Activation (5)").Select
    Range("A21:L6000").ClearContents
    Sheets("Action (5) ").Select
    Range("A21:L6000").ClearContents
    Sheets("Action (2)").Select
    Range("A21:L6000").ClearContents
    Sheets("Activation (3)").Select
    Range("A21:L6000").ClearContents
    Sheets("Action (3)").Select
    Range("A21:L6000").ClearContents


    End Sub

    could anyone help me to modify the code instead of listing all the sheet names and ranges?

    Thank you in advance.

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,262

    Re: Help needed for modifying code - clear contents

    Hi Sam D
    In future please view the forum rules before posting. Your post does not comply with rule #3.
    3. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing.
    So, do the following:
    Edit your post, highlight your code and click the [#] button at the top of the post window.

    Once that has been rectified, we will be able to post a solution...
    Last edited by sintek; 06-05-2018 at 06:56 AM.
    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 star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,098

    Re: Help needed for modifying code - clear contents

    Hello SamD,

    Something like the following should work:-

    Please Login or Register  to view this content.
    If there are sheets that need to be excluded from having data cleared, let us know.

    I hope that this helps.

    Cheerio,
    vcoolio.

  4. #4
    Valued Forum Contributor kasan's Avatar
    Join Date
    07-22-2009
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2010
    Posts
    680

    Re: Help needed for modifying code - clear contents

    Hi,
    Try this code.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-09-2018
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    86

    Re: Help needed for modifying code - clear contents

    Thank you so much for all your response... I forgot to mentioned that there are 4 sheets within the workbook are master/Output sheets.

    I want to clear all the Contents of the other sheets except for the 4 Output sheets.

    how should i modify this?

  6. #6
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,098

    Re: Help needed for modifying code - clear contents

    Hello Sam D,

    Try the following:-

    Please Login or Register  to view this content.
    Replace "Output sheet1" etc...... with the actual sheet names. Make sure that, in the code, they are spelled/punctuated exactly the same as the tab names.

    Cheerio,
    vcoolio.

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Help needed for modifying code - clear contents

    Or something like this.
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  8. #8
    Registered User
    Join Date
    05-09-2018
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    86

    Re: Help needed for modifying code - clear contents

    Thank you so much for all of your help !! That works great !!

  9. #9
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,098

    Re: Help needed for modifying code - clear contents

    You're welcome Sam. I'm glad that we were able to help.

    Cheerio,
    vcoolio.

+ 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] How to make my Code Clear Contents Code more efficient
    By eazy899 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-07-2018, 10:40 AM
  2. [SOLVED] VBA code to clear contents
    By Delta729 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-22-2017, 04:43 PM
  3. VBA Code to clear contents
    By tubbs1969 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-19-2016, 10:07 AM
  4. [SOLVED] Macro needed to clear contents
    By bigband1 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-30-2015, 12:38 PM
  5. VB Code to clear contents
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-04-2014, 01:35 AM
  6. Code to clear multiple contents
    By ABSTRAKTUS in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-24-2012, 02:13 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