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 |
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 |
All times are GMT +1. The time now is 05:49 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com