Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Reset public variable

Hi,
Do you know how to reset public variables at the beginning of macro without
using i = 0, j = 0 , ...
Thanks,
--
Alex St-Pierre
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Reset public variable

That is the way, why would you want another way?

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Alex St-Pierre" wrote in message
...
Hi,
Do you know how to reset public variables at the beginning of macro

without
using i = 0, j = 0 , ...
Thanks,
--
Alex St-Pierre



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Reset public variable

I have public variable because I use userform. When I restart macro.. all
variables are resets except public variable.. I have a lot of public
variables and I don't want to write all because I try to have the simple text
as possible.
--
Alex St-Pierre


"Bob Phillips" wrote:

That is the way, why would you want another way?

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Alex St-Pierre" wrote in message
...
Hi,
Do you know how to reset public variables at the beginning of macro

without
using i = 0, j = 0 , ...
Thanks,
--
Alex St-Pierre




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Reset public variable

Alex,

Try placing an End statement at the end of your macro.

For example

Option Explicit

Public i As Integer

Public Sub Test()
i = i + 1
MsgBox i
End ' Try this with and with out this End statement
End Sub

Without i retains its value from run to run. With it i is reset to 0
everytime you run the macro.



*** Sent via Developersdex http://www.developersdex.com ***
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Reset public variable

Thanks,
It works good with End!
I had the same problem with a userform. In a macro, I only disabled button
and when I restrart, the form is not reset. I use Unload userform1 to reset
the form. Does the End statement can also reset a form ?
--
Alex St-Pierre


"Edward Ulle" wrote:

Alex,

Try placing an End statement at the end of your macro.

For example

Option Explicit

Public i As Integer

Public Sub Test()
i = i + 1
MsgBox i
End ' Try this with and with out this End statement
End Sub

Without i retains its value from run to run. With it i is reset to 0
everytime you run the macro.



*** Sent via Developersdex http://www.developersdex.com ***



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Reset public variable

Alex,

Depends on where the user form gets its values from. If from a
ControlSource then no.

Be careful in placement of the End statement. Its like saying no matter
where I am in the execution of the macro stop everything and exit.


*** Sent via Developersdex http://www.developersdex.com ***
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Public variable Jack New Users to Excel 4 March 18th 06 09:35 PM
Public Variable Jason Excel Programming 4 April 12th 04 07:06 PM
Public variable is reset after addin macro completes - thread/focus pblm? hscowan Excel Programming 1 February 19th 04 09:07 PM
Public/Procedure Variable Otto Moehrbach[_6_] Excel Programming 2 February 6th 04 04:58 PM
public variable marwan hefnawy Excel Programming 1 September 5th 03 08:54 AM


All times are GMT +1. The time now is 07:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"