# is it possible to make a unit converter with vba

#### darro

##### Board Regular
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.

### Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a \$25,000 loan, 5% annual interest, 60 month loan.

#### Sahak

##### Well-known Member
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

##### Well-known Member
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.

#### darro

##### Board Regular
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
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?

Replies
5
Views
83
Replies
0
Views
103
Replies
2
Views
193
Replies
2
Views
269
Replies
6
Views
76

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

1,163,783
Messages
5,833,671
Members
430,222
Latest member
Nickkarl

### 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.

### Which adblocker are you using?

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

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