QP School

Full Version: Convert Fahrenheit to Celsius with VBA
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Example:

Sub ConvertToFahrenheit()
    Dim fahrenheitTemp As Double
    Dim celsiusTemp As Double

    fahrenheitTemp = 68
    celsiusTemp = (fahrenheitTemp - 32) * 5 / 9

    MsgBox fahrenheitTemp & " degrees Fahrenheit is equal to " & celsiusTemp & " degrees Celsius."
End Sub

Explanation:

This code defines a subroutine named ConvertToFahrenheit. 
It declares two variables fahrenheitTemp and celsiusTemp to store temperatures in Fahrenheit and Celsius, respectively. 
It sets the value of fahrenheitTemp to 68. 
The temperature in Fahrenheit is converted to Celsius using the formula (Fahrenheit - 32) * 5 / 9. 
The converted temperature is then displayed in a message box.

The formula (Fahrenheit - 32) * 5 / 9 is used to convert temperatures from Fahrenheit to Celsius. 
The MsgBox function displays the converted temperature in a message box.