Manipulating Text Box Values

business_analyst

Board Regular
Joined
Jun 5, 2009
Messages
99
Hello All,

I have created 14 Textboxes in a Userform. I would like to make it so that the numbers that a user enters into these text boxes must equal 100 (like 100%). However, the user is not required to fill out all 14 Textboxes. They may or may not fill out all Textboxes, but no matter what happens, I would like the Textboxes that do have numbers in them to equal to 100. Is there a way that I can create this type of check without hardcoding each value and adding them all?
Thanks
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
If you have a submit button, you could put this at the start of the Submit rounine

Code:
Dim Total As Double, i As Long

For i = 1 to 14
    Total = Total + Val(UserForm1.Controls("TextBox" & i) .Text)
Next i

If Total <> 100 then 
    MsgBox "TextBox entries must total to 100. Change and try again."
    Exit Sub
End If
 
Upvote 0
If you have a submit button, you could put this at the start of the Submit rounine

Code:
Dim Total As Double, i As Long

For i = 1 to 14
    Total = Total + Val(UserForm1.Controls("TextBox" & i) .Text)
Next i

If Total <> 100 then 
    MsgBox "TextBox entries must total to 100. Change and try again."
    Exit Sub
End If

That works perfectly mike, thanks very much for your assistance
 
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,442
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top