Patriot2879
Well-known Member
- Joined
- Feb 1, 2018
- Messages
- 1,259
- Office Version
- 2010
- Platform
- Windows
Hi good afternoon hope you can help me please, i have a UserForm2, where i have got 6 textboxes for example textbox1 is 'Miles' so when a number is entered in this textbox then al lthe other textboxes are updated with the conversion, for example textbox is for KM. i have tried the code below but it is not working the textboxes are not updating with the conversion. hope you can help me please?
VBA Code:
Private Sub CommandButton1_Click(Index As Integer)
Dim sngMiles As Single
'Make sure you have a mile value
If TextBox1.Text <> "" Then
sngMiles = Val(TextBox1.Text)
End If
If TextBox2.Text <> "" Then
sngMiles = Val(TextBox2.Text) * 0.621371192
End If
If TextBox3.Text <> "" Then
sngMiles = Val(TextBox3.Text) * 0.000621371192
End If
If TextBox4.Text <> "" Then
sngMiles = Val(TextBox4.Text) * 0.000189393939
End If
If TextBox5.Text <> "" Then
sngMiles = Val(TextBox5.Text) * 0.000568181818
End If
If TextBox6.Text <> "" Then
sngMiles = Val(TextBox6.Text) * 1.15077945
End If
'Now fill in the blanks
Calculate sngMiles
End Sub
Private Sub Calculate(ByVal sngMiles As Single)
TextBox1.Text = sngMiles
TextBox2.Text = sngMiles * 1.609344
TextBox3.Text = sngMiles * 1609.344
TextBox4.Text = sngMiles * 5280
TextBox5.Text = sngMiles * 1760
TextBox6.Text = sngMiles * 0.868976242
'Add formatting
TextBox1.Text = Format(TextBox1.Text, "#,##0.0#")
TextBox2.Text = Format(TextBox2.Text, "#,##0.0#")
TextBox3.Text = Format(TextBox3.Text, "#,##0.0#")
TextBox4.Text = Format(TextBox4.Text, "#,##0.0#")
TextBox5.Text = Format(TextBox5.Text, "#,##0.0#")
TextBox6.Text = Format(TextBox6.Text, "#,##0.0#")
End Sub
Last edited: