Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6164549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:00:46+00:00 2026-05-23T22:00:46+00:00

I have a static variable defined in a Sub: Private Sub assignVars() ‘ Use

  • 0

I have a static variable defined in a Sub:

Private Sub assignVars()
' Use this function to assign default values

    Static isSet As Integer

    If isSet <> 1 Then
        ' do something

        isSet = 1
    End If

End Sub

I have made some changes to my code and want to reset the static variable “isSet”. Is there any easy way to do this without closing Excel and opening it up again?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:00:47+00:00Added an answer on May 23, 2026 at 10:00 pm

    The easiest way to do this is to execute the End statement in the immediate window.

    However, this will destroy all stored state – i.e. all your module level variables, all static variables in all procedures, etc. And it’s abrupt; Unload and Terminate events don’t fire, etc.:

    http://msdn.microsoft.com/en-us/library/gg251671.aspx

    (I edited the stuff below after I re-read your question…)

    To cause a loss of state in just the one routine, you could manually comment out the declaration of isSet and then restore it. There is a setting you can make in the VBE under the Tools…Options menu, General tab, that will cause you to be notified when this kind of state loss happens. (It doesn’t alert for an invocation of End, though, presumably because you shouldn’t need any warning in that case.)

    You didn’t ask for this, but if you want to be able to reset the one static variable in the one procedure without editing any code, you’ll have to do something kludgy like this:

    Public Sub assignVars(Optional reset As Boolean)
        Static isSet As Integer
    
        If reset Then
            isSet = 0
    
            Exit Sub
        End If
    
        If isSet <> 1 Then
            isSet = 1
        End If
    End Sub
    

    Notice that I had to make your routine Public so that you can call it from the immediate window with a parameter of True when you want the reset.

    If it’s the case that you need some state that is accessible from outside of your procedure, in this case for the purposes of being able to manually reset it, you might consider a module-level variable rather than a Static procedure-level one. Then your routine can stay Private, there is no dirtying of its interface for reset purposes, and you can mess with the module-level variable all you want manually.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have defined a variable like this (C++): static const char str[] =
I need to mock a GrailsControllerClass interface. Instance should have a static variable defined.
Is it OK to have a static member variable defined in a base class,
Suppose you have a static global variable in your header file, and you use
Is there a way to have a mutable static variable in F# class that
I have used a static global variable and a static volatile variable in file
Static variable gotcha in php I am from Java background and have switched to
I have a couple of domain classes defined, Employee and EmployeeDesiredSkill, Employee has static
When a static member variable is declared private in a class, how can it
I have several service classes that have static methods and offer a service to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.