Reputation: 1
How do I write this function?
Function Fahrenheit2C()
Dim f As Integer
' Convert Fahrenheit to Celsius
Fahrenheit2C = (f - 32) / 1.8
End Function
I get "value errors", even though I am entering integers. Not sure what the issue here is. I tried to ask AI, but it is not working.
Upvotes: 0
Views: 152
Reputation: 6131
I would suggest NOT writing this function at all. Excel has built in functionality for converting basic units =CONVERT()
. In your case it would be =CONVERT(number, "F","C")
. There is no point of re-inventing the wheel.
Upvotes: 8
Reputation: 6829
You need to have an input value to utilize for the conversion:
Function ConvertFtoC(F As Double) As Double
ConvertFtoC = (F - 32) * 5 / 9
End Function
Upvotes: 2