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

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