Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

One-shot button

0

Is there any way that I can make a one-shot button?  I want to use a button only once after the worksheet has been copied.

Answer
Discuss

Answers

0
Selected Answer

There are many ways of doing that, but all of them require that you modify the code the button calls.

  1. Delete the button
  2. Hide the button
  3. Create a static variable to stop the code from running more than once.
    A Static variable retains its value between calls. So, if you set it to True whne you run the code for the first time it will still have that value when you try again. Here is a code snippet.

     
       Static Repeat As Boolean
    
        If Repeat Then
            MsgBox "You already performed this action"
        Else
            Repeat = True
            ' do your stuff here
        End If
Discuss


Answer the Question

You must create an account to use the forum. Create an Account or Login