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

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
821
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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
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,215,373
Messages
6,124,548
Members
449,170
Latest member
Gkiller

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