Textbox's return a number?

A

Adam

Hi

I have a userform where users enter infomation into a textbox, upon
hitting an enter button my code puts the infomation into the
spreadsheet.

ActiveCell.Offset(0, 0).Value = UserForm1.TextBox1.Value

My problem is some of the infomation must be a number i.e. a quantity.

How can i change the code to accept only a number in certain
textboxes?

Thanks in advance
 
J

Joel

You have to test if the number is numeric and if it is not then have the text
box re-open with an error message

Use isnumeric

do
if not isnumeric(UserForm1.TextBox1.Value) then
enter error message
end if
while not isnumeric(UserForm1.TextBox1.Value)

ActiveCell.Offset(0, 0).Value = UserForm1.TextBox1.Value
 
J

Jim Thomlinson

Use the textbox's change event along with isnumeric function to determine if
what is being entered is valid...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top