# VBA subroutine for celsius to fahrenheit?

#### BGiffin2004

##### New Member
Hello.
I am trying to figure out an Excel VBA subroutine for converting celsius to farhenheit. Anyone out there know how I can find the equation on the internet? Or anyone here who can show me the equation?
Thanks much.

### Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Something like this should work

Code:
``````Public Function CelsiustoF(ByVal C As Double) As Double
CelsiustoF = 32 + (9 / 5) * C
End Function``````

Thanks for that Richard. That might help.
But I was wondering about the actual VBA subroutine equation itself.
Thanks much.

Welcome to the board.

You could use the Convert Function in a sheet formula
It does require the Analysis toolpack from tools - addins

Sheet1

<TABLE style="PADDING-RIGHT: 2pt; PADDING-LEFT: 2pt; FONT-SIZE: 10pt; FONT-FAMILY: Arial,Arial; BACKGROUND-COLOR: #ffffff" cellSpacing=0 cellPadding=0 border=1><COLGROUP><COL style="FONT-WEIGHT: bold; WIDTH: 30px"><COL style="WIDTH: 64px"><COL style="WIDTH: 132px"><COL style="WIDTH: 132px"></COLGROUP><TBODY><TR style="FONT-WEIGHT: bold; FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center"><TD> </TD><TD>A</TD><TD>B</TD><TD>C</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">1</TD><TD>Value</TD><TD>Celcius to Fahrenheit</TD><TD>Fahrenheit to Celcius</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">2</TD><TD style="TEXT-ALIGN: right">0</TD><TD style="TEXT-ALIGN: right">32</TD><TD style="TEXT-ALIGN: right">0</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">3</TD><TD style="TEXT-ALIGN: right">25</TD><TD style="TEXT-ALIGN: right">77</TD><TD style="TEXT-ALIGN: right">25</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">4</TD><TD style="TEXT-ALIGN: right">32</TD><TD style="TEXT-ALIGN: right">89.6</TD><TD style="TEXT-ALIGN: right">32</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">5</TD><TD style="TEXT-ALIGN: right">40</TD><TD style="TEXT-ALIGN: right">104</TD><TD style="TEXT-ALIGN: right">40</TD></TR></TBODY></TABLE>
<TABLE style="FONT-SIZE: 10pt; BORDER-LEFT-COLOR: #00ff00; BORDER-BOTTOM-COLOR: #00ff00; COLOR: #000000; BORDER-TOP-STYLE: groove; BORDER-TOP-COLOR: #00ff00; FONT-FAMILY: Arial; BORDER-RIGHT-STYLE: groove; BORDER-LEFT-STYLE: groove; BACKGROUND-COLOR: #fffcf9; BORDER-RIGHT-COLOR: #00ff00; BORDER-BOTTOM-STYLE: groove"><TBODY><TR><TD>Spreadsheet Formulas</TD></TR><TR><TD><TABLE style="FONT-SIZE: 9pt; FONT-FAMILY: Arial" cellSpacing=0 cellPadding=2 border=1><TBODY><TR style="FONT-SIZE: 10pt; BACKGROUND-COLOR: #cacaca"><TD>Cell</TD><TD>Formula</TD></TR><TR><TD>B2</TD><TD>=CONVERT(A2,"C","F")</TD></TR><TR><TD>C2</TD><TD>=CONVERT(B2,"F","C")</TD></TR><TR><TD>B3</TD><TD>=CONVERT(A3,"C","F")</TD></TR><TR><TD>C3</TD><TD>=CONVERT(B3,"F","C")</TD></TR><TR><TD>B4</TD><TD>=CONVERT(A4,"C","F")</TD></TR><TR><TD>C4</TD><TD>=CONVERT(B4,"F","C")</TD></TR><TR><TD>B5</TD><TD>=CONVERT(A5,"C","F")</TD></TR><TR><TD>C5</TD><TD>=CONVERT(B5,"F","C")</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>

Excel tables to the web >> http://www.excel-jeanie-html.de/index.php?f=1" target="_blank"> Excel Jeanie HTML 4

Right Peter. Thank-you for your help.
I have this equation already. It is not a subroutine though; but a function. Would you be able to help me convert that function equation to a subroutine equation?
Thanks!

Try

Code:
``````Private Sub CelsiustoF(C As Double, F As Double)
F = 32 + (9 / 5) * C
End Sub

Sub test()
Dim fahr As Double
Call CelsiustoF(20, fahr)
MsgBox fahr
End Sub``````

I was going to show a formula and a vba statement that would return the (converted) results, but I see those are provided already but you say you want the equation.

converting 68 degrees F to C:
Step 1: 68 - 32 is 36
Step 2: 5 divided by 9 is 0.5555555555555
Step 3: multiply the repeating decimal by 36
Step 4: your solution is 20

Now, convert 20 degrees C to F to check your work.
Step 1: 9 divided by 5 is 1.8
Step 2: 1.8 multiplied by 20 is 36
Step 3: 36 plus 32 = 68

Is this what you're looking for?

Hope it helps.

Thanks Peter.
I'll certainly check the code on the workbook.
Best.

I got my answer to this one. Thanks to everyone who contriibuted.

Replies
4
Views
152
Replies
4
Views
126
Replies
4
Views
205
Replies
0
Views
62
Replies
3
Views
135

1,203,174
Messages
6,053,929
Members
444,694
Latest member
JacquiDaly

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

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