简体   繁体   中英

VBA Error: Ambiguous Name Detected (Excel 2010)

I am very new to VBA. I am sorry if my question is very easy. I have a question. When I run the following code, I get the following error message:

Compiler Error: Ambiguous Name Detected: faren

Can anyone please explain what part of my code is wrong?

Option Explicit

Dim n As Double
Private faren As Integer
Dim result As Double

Function faren(n)
faren = (9 / 5) * (n + 32)
End Function

Function c(n)
Dim c As Long
c = (5 / 9) * (n - 32)
End Function

Sub test()
result = faren(32)
MsgBox "the degree in farenheit is " & result & "Farenheit."
End Sub

You declare faren two times. First one Private faren As Integer and second one Function faren(n)

To avoid ambiguous names you can delete Private faren As Integer and amend the function line like this: Function faren(n) As Integer

Edit: I don't know if you declare faren intentionally as Integer instead of Double , but I want you to see the following results to compare the difference:

When Function faren(n) As Integer is used n = 32 --> result = 115

When Function faren(n) As Double is used n = 32 --> result = 115.2

You might want to consider declaring c as double in the same way because it affects the result as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM