How can i change the format of a textbox

tiguil

Board Regular
Joined
Jul 21, 2004
Messages
88
I'm using a textbox to get some numbers. I seems that i'm getting trought that TextBox field are text and not numbers. How can i transform the data in a number. Down below is the code that i'm using. Can someone help me please. Thanks.

Private Sub TxtBox1_AfterUpdate()
x = Format(TxtBox1.Value, 0)
End Sub

Private Sub CommandButton1_Click()
If OptBtn1.Value = True Then
CopySem
ElseIf OptBtn2.Value = True Then
CopyMois
End If
End Sub

Sub CopySem()
Selection.Copy
y = 0
Do Until y = x
ActiveCell.Offset(0, 2).Select
ActiveSheet.Paste
y = y + 1
Loop
End Sub

Sub CopyMois()
Selection.Copy
y = 0
Do Until y = x
ActiveCell.Offset(0, 3).Select
ActiveSheet.Paste
y = y + 1
Loop
End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Assuming that X is the global or the form variable, try:
Dim X as Long
' … your code
X = Val(TxtBox1)
' … your code
 
Upvote 0

Forum statistics

Threads
1,225,400
Messages
6,184,762
Members
453,255
Latest member
excelbit

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