View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Charlie Charlie is offline
external usenet poster
 
Posts: 703
Default Public Variable not maintaining value.

move it to a module such as Module1

"Mark" wrote:

I have the following code segment. WbkCount is a public variable which is
declared in ThisWorkbook.

I want that variable to count how many times the the user creates a certain
report.

This code is initialized when a command button is selected.

So far, every time I run the code, Msgbox wbkcount is returning a "1"... no
matter how many times I run it. Oddly, I can't find any place where the
variable could be resetting.


result = MsgBox("Please confirm that you wish to create the " & Counter & "
selected report(s).", vbOKCancel, "Continue?")
If result = vbOK Then
WbkCount = WbkCount + 1
ReDim Preserve Wbks(0 To WbkCount)
Application.SheetsInNewWorkbook = Counter
MsgBox WbkCount
Set Wbks(WbkCount) = Workbooks.Add
For i = 1 To Counter
Worksheets(i).Name = Reported(i)
Next i
Else
Exit Sub
End If