Is there a way to assign all digits of a number entered in a userform textbox to a variable?

bhat88

New Member
Joined
Jun 24, 2015
Messages
2
I hope the title is not confusing. Well, let me explain.

I have a userform with a textbox. I assign the user-entered value to a variable like this:

Dim balance as Long
balance = UserForm1.TextBox1.Value

Now if user enters 1234 in the textbox, first 1 gets stored in 'balance' then 2, then 3 and then 4. I want 1234 to be stored in 'balance' at a time which is required for looping up next my code. Is there a way?
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Why do you need a variable? The TEXTBOX is the variable.
If the user enters 1234 into textbox1, then
textbox1.value will be 1234.

I cant see from your example but you may have this code under CHANGE event. dont put it there. Heck, dont use the variable ...the box is the variable.
 
Upvote 0
Hi, thank you for the quick help. I agree I can use the textbox as the variable but just for the ease, I am assigning it to a variable which I am going to use many times in my code. Anyway, my point is that 1234 is getting stored digit-by-digit. A simple code example:


Dim balance as Int
balance = UserForm1.TextBox1.Value
MsgBox balance

As soon as user enter 1, the message box pops-up 1. Close it and enter 2, it pops-up 12 and so on. I want 1234 to be popped-up at once.
 
Upvote 0
Sounds like you are using the textbox's Change event, try another event, for example Exit.
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,431
Members
452,326
Latest member
johnshaji

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