Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am revisiting this continueing issue I am having and I apologize to all
those who have tried to help me thus far. Here is a simplified version of my situation. I have a UserForm that opens with 2 Buttons and 3 CheckBoxes. If my user opens the Userform and sets all checkboxes = True and clicks Calculate var1 = 100, var2 = 200, var3 = 300, (Note: UserForm is still open, thus varibles values are not destroyed and variables are declared in the Declarations section). The problem happens when my user sets CheckBox1 & 2 = True and CheckBox3 = False, var1 = 100, var2 = 200, var3 = 300. It should be var1 = 100, var2 = 200, var3 = 0, why is this? I thought the For...Loop set the values = 0. I also have an Error indicated below, why? Basically, I want to make all the variable values equal to 0 at the begining of the btnApply_Click procedure and then calculate the variable values. Note: I don't want to use Else var1 = 0, because this would make the code sloppy to me. Option Explicit Dim var1 As Single Dim var2 As Single Dim var3 As Single Private Sub btnApply_Click() Dim myArray As Variant Dim i As Long ' array of allocated part quantities myArray = Array(var1, var2, var3) ' resets variables For i = LBound(myArray) To UBound(myArray) myArray(i) = Empty Next i MsgBox "var1 = " & var1 & " : var1 should equal 0" MsgBox "var2 = " & var2 & " : var2 should equal 0" MsgBox "var3 = " & var3 & " : var3 should equal 0" Call Calculate ' array of allocated part quantities myArray = Array(var1, var2, var3) MsgBox "After Calculation var1 = " & var1 MsgBox "After Calculation var2 = " & var2 MsgBox "After Calculation var3 = " & var3 ' apply values to worksheet For i = LBound(myArray) To UBound(myArray) If Not IsEmpty(myArray(i)) Then Error= Sheets("Calculator").Cells(i, 1) = myArray(i) End If Next i End Sub Private Sub Calculate() If CheckBox1 = True Then var1 = 100 End If If CheckBox2 = True Then var2 = 200 End If If CheckBox3 = True Then var3 = 300 End If End Sub -- Cheers, Ryan |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Count occurances of equal values in two col. - array within SUMPRO | Excel Worksheet Functions | |||
Clearing Variable Values in Array using For...Next | Excel Programming | |||
Make all variable in Array = Empty each click of a Button on Userf | Excel Programming | |||
Can I make array position A(12) into a variable A(12*n) ? | Excel Worksheet Functions | |||
how do I make single character as a variable in an array | Excel Worksheet Functions |