is it possible to make a unit converter with vba

darro

Board Regular
Joined
Mar 10, 2009
Messages
208
Hi, I have to convert degrees F into degrees C and vice versa and I know the convert function in excel is there but I don't want to have to use a formula in a cell all the time. Is there a way to run the function using a macro?

So, for instance, i run thee macro and a comment box opens where i can select the cell with the number to convert, and then it gives me options of the unit i want it from and to, and then it changes to the new value. Is this possible?

It would be a timesaver for me if so.

Thanks in advance.
 

Some videos you may like

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Sahak

Well-known Member
Joined
Nov 10, 2006
Messages
884
Hi Darro,

Maybe it will work for you.
Make userForm with Controls CommandButton1 (for Calculate), TextBox1(for Fahrenheit) & Label1 (for answer in Celsius).
Code:
Private Sub CommandButton1_Click()
    Dim Degry_F As Single
    Label1.Caption = Format((Val(TextBox1.Value) / 1.8) - 32, "0.0")
End Sub

1. Enter a number in TextBox1 (to be converted Fahrenheit into Celsius)
2. Push button CommandButton1
3. Get answer on Label1 in Celsius
 

ColinKJ

Well-known Member
Joined
Jan 27, 2009
Messages
983
Hi darro,

An alternative,

Paste these into a standard Module

Code:

Sub CF()
ro = ActiveCell.Row: co = ActiveCell.Column
b = Val(Cells(ro, co))
b = (b * 1.8) + 32
Cells(ro, co) = b
End Sub

Sub FC()
ro = ActiveCell.Row: co = ActiveCell.Column
b = Val(Cells(ro, co))
b = (b - 32) / 1.8
Cells(ro, co) = b
End Sub

Code:

Assign sub CF to Ctrl+F and sub FC to Ctrl+C.

Enter a value in a cell, select the cell. If you want it converted to F, Press Ctrl+F, if you want in C, Press Ctrl+C.

ColinKJ
 

darro

Board Regular
Joined
Mar 10, 2009
Messages
208
Thanks Colin, thats perfect, works without a hitch. Thanks Sahak, I couldnt get it to work, thanks for your help both of you.
 

darro

Board Regular
Joined
Mar 10, 2009
Messages
208
If I wanted to, what would be involved in making a converter that sat in the toolbar of excel. Like the calculator that can be added from the customize toolbar option.

Could it be made to include all the CONVERT functions? enter the value to convert, select the "from unit" and "to unit" and there ya go!

What do you think?
 

Watch MrExcel Video

Forum statistics

Threads
1,122,564
Messages
5,596,875
Members
414,106
Latest member
Tigretto

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
Top