Excel undo my sub

Posted on 2011-10-15
Last Modified: 2012-05-12
Hello experts

I have the following procedure that applies styling to the selected cells, but I want to be able to press the Undo button.

How would I go about doing an undo procedure? I understand that it would need to take note of the range of cells and store the font name/size/bold/color for each cell and then reapply it, but I'm really not sure how to go about that. Maybe I'm off track with my thoughts there. Not sure. Help!!

Public Sub StyleHeading()
  ApplyHeading Selection
End Sub

Public Function ApplyHeading(ByVal r As Range)
 Dim c
 For Each c In r
    With c.font
        .Name = "Arial"
        .Size = 12
        .Bold = True
        .Color = RGB(0, 100, 177)
    End With
End Function

Open in new window

Question by:Fi69
    1 Comment
    LVL 19

    Accepted Solution


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
    The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
    This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now