This is for Fahrenheit to Celsius

Rileys98

New Member
Joined
Jun 28, 2022
Messages
4
Office Version
  1. 2019
Platform
  1. Windows
Trying to use an excel formula in a VBA code. I'm sure I have the syntax wrong. Appreciate the correct way to write it.
A message box comes up and you put a number in it. I want it converted and then variable b to state what it is.
I'm sure I'm falling down with syntax after be =
You can see I'm new at this so appreciate any help.

Dim a As Variant
Dim b As Variant

a = Application.InputBox(prompt:="Type in a number", Title:="Type a Fahrenheit temperature", Default:="Type your temperature here", Type:=1)

b=Application.WorksheetFunction.(Convert(a,"F","C")

MsgBox "Celsius equivalent degrees:" & vbCrLf & Round(b, 1)
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi & welcome to MrExcel.
You just need to remove the ( from before Convert
 
Upvote 0
Solution
Glad to help & thanks for the feedback.
 
Upvote 0
Fluff got you sorted but, if you want to, you could make it slightly more compact.
Code:
Sub Maybe()
Dim tempF As Long
tempF = Application.InputBox("Temperature in Fahrenheit:", "Convert to Celsius.", "Enter Temperature Here!", 1)
MsgBox Format(WorksheetFunction.Convert(tempF, "F", "C"), "#.00")
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,461
Messages
6,124,954
Members
449,198
Latest member
MhammadishaqKhan

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