VBA EXPERTS: I need to make a user form to convert from metric to inches

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
831
Office Version
  1. 365
Platform
  1. Windows
Thanks for looking at my post. I need to create a Userform that will pop up on clicking a form control button that has a text box some one can enter in a number in metric and click a button and it convert it to inches.
Example: 145.6 to 5.7323
mm inch
 
Hi

The way you are doing it it will try to update the textbox value each time you enter a character which is not what your want.

Just for testing try the following:

- remove or comment the textbox Change event procedure

- paste this DoubleClick event procedure

Code:
Private Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
If IsNumeric(Me.TextBox1.Value) Then
    Me.TextBox1.Value = Me.TextBox1.Value / 25.4
End If
End Sub

- execute the form, enter a number in the textbox and then doubleclick on it
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
ok, I changed it up to work from a button and it seems to work fine. Is there something I can add for it to do the calculation just one time? I noticed that every time i hit the button it keeps calculating. This is what Im currently using
Private Sub CommandButton1_Click()
If IsNumeric(Me.TextBox1.Value) Then
Me.TextBox1.Value = Me.TextBox1.Value / 25.4
End If
End Sub
 
Upvote 0
Why not add a second text box and do the calculation there? That way you have the original value for reference.
 
Upvote 0
that would be great
would the code need to look something like this?
Private Sub CommandButton1_Click()
If IsNumeric(Me.TextBox1.Value) Then
Me.TextBox1.Value = Me.TextBox2.Value / 25.4
End If
End Sub
 
Upvote 0
Almost, you need to reverse the order in the calculation line:

Code:
Private Sub CommandButton1_Click()
If IsNumeric(Me.TextBox1.Value) Then
    Me.TextBox2.Value = Me.TextBox1.Value / 25.4
    End If
End Sub
 
Upvote 0
Is there away to make text box 2 were there cannot be anything typed in it?? Thanks
 
Upvote 0
Thanks I missed that.. How about formatting textbox2 to fraction? can this be done?
 
Upvote 0
Me.Textbox2.Text = Format(Me.Textbox1.Value / 25.4,"# ?/??") or something like that...? (Untested)
 
Upvote 0

Forum statistics

Threads
1,223,740
Messages
6,174,223
Members
452,552
Latest member
Kleets

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