+ Reply to Thread
Results 1 to 8 of 8

Clear format & everything from worksheet, except a range of cells' values (VBA) & back

  1. #1
    Registered User
    Join Date
    10-30-2023
    Location
    Honduras
    MS-Off Ver
    2021
    Posts
    10

    Clear format & everything from worksheet, except a range of cells' values (VBA) & back

    Hi, I was wondering if there is a way to toggle clear/hide everything from a worksheet except from a range of cells I could specify and also bring everything back using VBA. The idea is that I want to print a, empty table and later on, print the values over that same paper once I'm ready to do so, then restore the original format once again (using a macro button to toggle it on/off). The range of cells I want to keep their values is C9:S33, everything else: format, conditional formating, objects, text, borders would be cleared/hid, and, with the same button with macro bring back everything once I need it back again.

    Hope I could explain myself.

    Thank you very much
    Screenshot_21.jpg
    Last edited by RobotMan; 11-27-2023 at 09:34 PM.

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Clear format & everything from worksheet, except a range of cells' values (VBA) & back

    Hi there,

    See if the following code gets you moving in the right direction - it works by copying a range of values between worksheets, one of which is formatted and the other of which is not:

    Please Login or Register  to view this content.
    The highlighted values may be altered to suit your requirements.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  3. #3
    Registered User
    Join Date
    10-30-2023
    Location
    Honduras
    MS-Off Ver
    2021
    Posts
    10

    Re: Clear format & everything from worksheet, except a range of cells' values (VBA) & back

    Hi Greg, thank you for your code, unfortunately I don't know what am i doing wrong because when applied, the code do not change anything or there is a run-time error. In fact I don't know what to do, I introduced the code as a module, then created 2 buttons (1 for ClearFormatting and 1 for ShowFormatting) and assigned the macro to each. But when I press any button then the result is negative. What is it that I am missing? Should I do something else? I see in at the beginning of your code:
    Please Login or Register  to view this content.
    And I do not understand about the Sheet 1 and Sheet 2, do I have to create something else? Can you explain this to me, please?

    Thank you again and sorry for my unexperience in VBA

    Mike

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Clear format & everything from worksheet, except a range of cells' values (VBA) & back

    Hi again,

    Can you post a sample workbook with the worksheet shown in your initial post?

    If you can do this I will add the "Without Formatting" worksheet and the necessary code.

    Please Login or Register  to view this content.
    This value should be the name of a new worksheet without formatting.

    This value should be the name of your existing worksheet with formatting.


    Regards,

    Greg M

  5. #5
    Registered User
    Join Date
    10-30-2023
    Location
    Honduras
    MS-Off Ver
    2021
    Posts
    10

    Re: Clear format & everything from worksheet, except a range of cells' values (VBA) & back

    Hi Greg, with your explanation about the sheets I made it work, but now I face a new problem: My file contains 6 worksheets and I would like to know if you could modify your code so this would work with all six pages, since your code only defines 1 SHEET__WITH_FORMATTING. I'm sending you my file (hope I did it right). Thank you very much!
    Attached Files Attached Files

  6. #6
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Clear format & everything from worksheet, except a range of cells' values (VBA) & back

    Hi again,

    See if the attached version of your workbook does what you need.

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    10-30-2023
    Location
    Honduras
    MS-Off Ver
    2021
    Posts
    10

    Re: Clear format & everything from worksheet, except a range of cells' values (VBA) & back

    Hi Greg, It works wonderful, thank you for your big help. Appreciate it.

  8. #8
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Clear format & everything from worksheet, except a range of cells' values (VBA) & back

    Hi again,

    Many thanks for your feedback.

    You're welcome - glad I was able to help.

    Regards,

    Greg M


    P.S. Many thanks also for the Reputation increase - much appreciated!
    Last edited by Greg M; 12-02-2023 at 09:34 AM. Reason: P.S. added

+ 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. Adding A "Clear" Button to Worksheet to Clear a Range of Data
    By theexcelnovice123 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-06-2021, 05:53 AM
  2. [SOLVED] VBA code for 2 buttons that can clear cells in a row then second button to bring data back
    By Hillster in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 11-08-2019, 09:14 PM
  3. [SOLVED] Changing color format in cells based on 3 range values in a different column cells.
    By konkonmike in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 07-08-2019, 08:11 AM
  4. [SOLVED] Macro to copy cells from a selected range and just paste values back to that same range
    By catscats11 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-18-2019, 02:59 PM
  5. [SOLVED] Help with code to creat Reset button to clear cells and copy back the original formula
    By rv02 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-30-2015, 02:25 PM
  6. Copy Values from WorkSheet back to Another Workbook Replacing Values in Worksheet
    By bobwilson in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-03-2006, 04:50 PM
  7. [SOLVED] Automatically clear values from a range of selected cells
    By John Davies in forum Excel General
    Replies: 1
    Last Post: 06-28-2005, 12:05 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