J
jeff
Here’s what I’m trying to do. The user fills out UserForm6 that
already has a number in TextBox22 when it comes up. This number is
from a previous form. There are 16 TextBoxes in UserForm6, and the
user will enter numbers in some or all of these boxes. The idea is to
have the sum of these 16 boxes equal the number that was already in
TextBox22.
I have code that will sum up the 16 boxes, and put that total in
TextBox23. I want the numbers from boxes 22 and 23 to equal. If they
don’t when the user clicks OK, then the user will be told they have to
match. Right now, I have a MsgBox come up telling the user they don’t
match.
At that point I want the user to be able to change the numbers in
those 16 boxes, and try it again. Then the 2 TextBoxes should be
compared again to see if they match totals.
I’ve tried various If then, and Do Until codes, but the best I can
come up with is what turns into an endless loop, or it will not test
the condition again. I can’t get it to re-calculate the total from the
boxes, and test against TextBox22 again.
Here’s what I have so far:
***this attempt calculates the sum of the 16 TextBoxes, and shows that
number in TextBox23. And, it will recalculate the TextBox23 correctly
after each change by the user. So far, so good. However, when the
number finally does match, it still comes up with the MsgBox and
doesn’t seem to re-test the IF-Then condition again. No matter what,
the MsgBox will come up. Also, if TextBoxes 22 & 23 DO match on the
1st try, it still comes up with the MsgBox.
Private Sub CommandButton1_Click()
'OK
ChkTotal 'sub in same UF that sums the total of the 16 TextBoxes
If TextBox23.Value = TextBox22.Value Then
AllocateDeposit 'Sub in same UF This is the final routine - done
only after TextBoxes 22 & 23 match.
Else
MsgBox "Total allocations must equal the Deposit value"
End If
End Sub
‘***This was an alternative solution I was working on. Upon clicking
OK, the MsgBox comes up no matter what the user enters in the 16
boxes. It’s an endless loop, and I have to Ctrl Break to stop the
macro.
Private Sub CommandButton1_Click()
‘OK
Do Until TextBox23.Value = TextBox22.Value
ChkTotal 'module below
If TextBox23.Value = TextBox22.Value Then
AllocateDeposit 'module below
Else
MsgBox "Total allocations must equal the Deposit value"
End If
Loop
End Sub
Am I close with either attempt? If anyone can help, I’d appreciate
it.
Thanks,
jeff
already has a number in TextBox22 when it comes up. This number is
from a previous form. There are 16 TextBoxes in UserForm6, and the
user will enter numbers in some or all of these boxes. The idea is to
have the sum of these 16 boxes equal the number that was already in
TextBox22.
I have code that will sum up the 16 boxes, and put that total in
TextBox23. I want the numbers from boxes 22 and 23 to equal. If they
don’t when the user clicks OK, then the user will be told they have to
match. Right now, I have a MsgBox come up telling the user they don’t
match.
At that point I want the user to be able to change the numbers in
those 16 boxes, and try it again. Then the 2 TextBoxes should be
compared again to see if they match totals.
I’ve tried various If then, and Do Until codes, but the best I can
come up with is what turns into an endless loop, or it will not test
the condition again. I can’t get it to re-calculate the total from the
boxes, and test against TextBox22 again.
Here’s what I have so far:
***this attempt calculates the sum of the 16 TextBoxes, and shows that
number in TextBox23. And, it will recalculate the TextBox23 correctly
after each change by the user. So far, so good. However, when the
number finally does match, it still comes up with the MsgBox and
doesn’t seem to re-test the IF-Then condition again. No matter what,
the MsgBox will come up. Also, if TextBoxes 22 & 23 DO match on the
1st try, it still comes up with the MsgBox.
Private Sub CommandButton1_Click()
'OK
ChkTotal 'sub in same UF that sums the total of the 16 TextBoxes
If TextBox23.Value = TextBox22.Value Then
AllocateDeposit 'Sub in same UF This is the final routine - done
only after TextBoxes 22 & 23 match.
Else
MsgBox "Total allocations must equal the Deposit value"
End If
End Sub
‘***This was an alternative solution I was working on. Upon clicking
OK, the MsgBox comes up no matter what the user enters in the 16
boxes. It’s an endless loop, and I have to Ctrl Break to stop the
macro.
Private Sub CommandButton1_Click()
‘OK
Do Until TextBox23.Value = TextBox22.Value
ChkTotal 'module below
If TextBox23.Value = TextBox22.Value Then
AllocateDeposit 'module below
Else
MsgBox "Total allocations must equal the Deposit value"
End If
Loop
End Sub
Am I close with either attempt? If anyone can help, I’d appreciate
it.
Thanks,
jeff