chris-evans
Board Regular
- Joined
- Feb 19, 2002
- Messages
- 73
Hi all
I was hoping someone could help me. Many years ago i built a userform, through which i can select two sets of numbers and the form will then analyse the numbers for me. It has always worked fine and continues to do so.
I want to change it though and add another calc to give me the % difference between the two sets of numbers. My problem is i am quite rusty on my VBA and intuitively i am doing it right i cannot remember where i would have declared the variables for the userform. Where would i declare this? I can write the code to do the calc and pass it through to the label, i just can't find where or how i would have defined the other variables!
I have two simple scripts, i have underlined and made bold my amends, I know everything else works fine:
1) to compare numbers
Private Sub cbComparison_Click()
lbOriginalValueHolder = WorksheetFunction.Text(lbNumberSumHolder, "#,##0.000000000000000;(#,##0.000000000000000)")
lbComparisonValueHolder = WorksheetFunction.Text(WorksheetFunction.Sum(Selection), "#,##0.000000000000000;(#,##0.000000000000000)")
lbDeltaValueHolder = lbOriginalValueHolder - lbComparisonValueHolder
lbDeltaValuePercentHolder = lbOriginalValueHolder / lbComparisonValueHolder - 1
If lbDeltaValueHolder = 0 Then
lbDeltaGood.Caption = "No Delta"
Else
lbDeltaGood = "Delta"
End If
Format_Labels
End Sub
2) to format the datalabels
If OBWholeNumber = True Then
Select Case SBDecimal
Case 0
lbNumberSum = WorksheetFunction.Text(lbNumberSumHolder, "#,##0;(#,##0)")
lbOriginalValue = WorksheetFunction.Text(lbOriginalValueHolder, "#,##0;(#,##0)")
lbComparisonValue = WorksheetFunction.Text(lbComparisonValueHolder, "#,##0;(#,##0)")
lbDeltaValue = WorksheetFunction.Text(lbDeltaValueHolder, "#,##0;(#,##0)")
lbDeltaValuePercent = WorksheetFunction.Text(lbDeltaValuePercentHolder, "#,##0.0;(#,##0.0)")
Case 1 - note, this then goes through various case analyses depending on what decimal place i select on the user form.
When i now launch the form it just says "compile error : Variable not defined"
Any ideas where i'm going wrong would be appreciated.
Many thanks in advance!
Chris
I was hoping someone could help me. Many years ago i built a userform, through which i can select two sets of numbers and the form will then analyse the numbers for me. It has always worked fine and continues to do so.
I want to change it though and add another calc to give me the % difference between the two sets of numbers. My problem is i am quite rusty on my VBA and intuitively i am doing it right i cannot remember where i would have declared the variables for the userform. Where would i declare this? I can write the code to do the calc and pass it through to the label, i just can't find where or how i would have defined the other variables!
I have two simple scripts, i have underlined and made bold my amends, I know everything else works fine:
1) to compare numbers
Private Sub cbComparison_Click()
lbOriginalValueHolder = WorksheetFunction.Text(lbNumberSumHolder, "#,##0.000000000000000;(#,##0.000000000000000)")
lbComparisonValueHolder = WorksheetFunction.Text(WorksheetFunction.Sum(Selection), "#,##0.000000000000000;(#,##0.000000000000000)")
lbDeltaValueHolder = lbOriginalValueHolder - lbComparisonValueHolder
lbDeltaValuePercentHolder = lbOriginalValueHolder / lbComparisonValueHolder - 1
If lbDeltaValueHolder = 0 Then
lbDeltaGood.Caption = "No Delta"
Else
lbDeltaGood = "Delta"
End If
Format_Labels
End Sub
2) to format the datalabels
If OBWholeNumber = True Then
Select Case SBDecimal
Case 0
lbNumberSum = WorksheetFunction.Text(lbNumberSumHolder, "#,##0;(#,##0)")
lbOriginalValue = WorksheetFunction.Text(lbOriginalValueHolder, "#,##0;(#,##0)")
lbComparisonValue = WorksheetFunction.Text(lbComparisonValueHolder, "#,##0;(#,##0)")
lbDeltaValue = WorksheetFunction.Text(lbDeltaValueHolder, "#,##0;(#,##0)")
lbDeltaValuePercent = WorksheetFunction.Text(lbDeltaValuePercentHolder, "#,##0.0;(#,##0.0)")
Case 1 - note, this then goes through various case analyses depending on what decimal place i select on the user form.
When i now launch the form it just says "compile error : Variable not defined"
Any ideas where i'm going wrong would be appreciated.
Many thanks in advance!
Chris