VBA subroutine for celsius to fahrenheit?

BGiffin2004

New Member
Joined
Nov 10, 2011
Messages
35
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

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.
<b>Excel 2010</b><table cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF;border: 1px solid;border-collapse: collapse; border-color: #BBB"><colgroup><col style="background-color: #DAE7F5" /><col /><col /></colgroup><thead><tr style=" background-color: #DAE7F5;text-align: center;color: #161120"><th></th><th>A</th><th>B</th></tr></thead><tbody><tr ><td width="25px" style="color: #161120;text-align: center;">1</td><td width="63px" style=";">Celsius</td><td width="63px" style=";">Fahrenheit</td></tr><tr ><td width="25px" style="color: #161120;text-align: center;">2</td><td width="63px" style="text-align: right;;">100</td><td width="63px" style="text-align: right;;">212</td></tr><tr ><td width="25px" style="color: #161120;text-align: center;">3</td><td width="63px" style="text-align: right;;">100</td><td width="63px" style="text-align: right;;">212</td></tr></tbody></table><p style="width:3.6em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid #BBB;border-top:none;text-align: center;background-color: #DAE7F5;color: #161120">Sheet1</p><br /><br /><table cellpadding="2.5px" rules="all" style=";border: 2px solid black;border-collapse:collapse;padding: 0.4em;background-color: #FFFFFF" ><tr><td style="padding:6px" ><b>Worksheet Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: #FFFFFF;border-collapse: collapse; border-color: #BBB"><thead><tr style=" background-color: #DAE7F5;color: #161120"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: #DAE7F5;color: #161120">B2</th><td style="text-align:left">=9/5*A2+32</td></tr><tr><th width="10px" style=" background-color: #DAE7F5;color: #161120">A3</th><td style="text-align:left">=5/9*(<font color="Blue">B3-32</font>)</td></tr></tbody></table></td></tr></table><br />
 
Upvote 0
Something like this should work

Code:
Public Function CelsiustoF(ByVal C As Double) As Double
CelsiustoF = 32 + (9 / 5) * C
End Function
 
Upvote 0
Thanks for that Richard. That might help.
But I was wondering about the actual VBA subroutine equation itself.
Thanks much.
 
Upvote 0
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
 
Upvote 0
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!
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,223,143
Messages
6,170,351
Members
452,322
Latest member
simon sorie

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