+ Reply to Thread
Results 1 to 2 of 2

Resetting Variable value's

  1. #1
    Forum Contributor
    Join Date
    02-07-2011
    Location
    netherlands
    MS-Off Ver
    Excel 2003
    Posts
    128

    Resetting Variable value's

    I got some issue with my code.

    Somehow when i run it multiple times the script wil function wrong and diffrent from the 1 time before.

    Is there something that will reset all variable values to empty?

    i know yo ucan do this manualy in VBA but i want it in code.

    Else i have to loop trough all varaible's and put them Empty.
    or reopen the workbook but that is not an option for every little change.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,529

    Re: Resetting Variable value's

    It would probably help if we could see the code, ideally in the context of a workbook.

    If you "scope" your variables effectively, they should be easy enough to locate and reset.

    You should define (Dim) your variables at the "right" level. For example, if a variable is only used within a subroutine or function, define it within that subroutine/function. If it's used across the module, you can declare it outside the subroutines so you can pass information between the subroutines. Public variables have even wider scope.

    That said, it is better to avoid widening the scope unnecessarily and you can pass variables between the routines in the subroutine call.

    Hope this helps.

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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