Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Font Name in Function 2

Status
Not open for further replies.

michaelbr55

Programmer
Oct 8, 2002
70
0
0
I have a function which I want to return a value and change the font of the cell where the return value is to be.
But I can't get it to work, any ideas?
Here is the code
Code:
Function Power_3Ph(Optional Voltage As Variant = 0, Optional Current As Variant = 0, Optional Resistance As Variant = 0, Optional cosø As Variant = 0, Optional Phase_Angle As Variant = 0) As Variant
Dim E As Double, I As Double, R As Double, C As Double, A As Double, P As Double
' I = P/?3(Vl cos(f)) or I = P/3(Vp cos(f))
'P = sqr(3)(VlIl cos(f)) or P = 3(VpIp cos(f))
E = Voltage
I = Current
R = Resistance
C = cosø
A = Phase_Angle
    If cosø = 0 Then
        C = Cos(Phase_Angle)
    End If
    
   [red] ActiveCell.font.Name = "Symbol"[/red]

    If Resistance = 0 Then
        P = Rt3 * (E * I * C)
       Power_3Ph = IIf(P > 1000, Format(P / 1000, "#.## kW"), Format(P, "0.## W"))
        'Power_3Ph = P
        Exit Function
    End If
    
    If Current = 0 Then
        P = Rt3 * E ^ 2 * C / R
        Power_3Ph = IIf(P > 1000, Format(P / 1000, "#.## kW"), Format(P, "0.## W"))
    Exit Function
    End If
    
    If Voltage = 0 Then
        P = Rt3 * I ^ 2 * R * C
        Power_3Ph = IIf(P > 1000, Format(P / 1000, "#.## kW"), Format(P, "0.## W"))
    Exit Function
    End If
    
End Function

if I add a watch to ActiveCell it gives the following result

ActiveCell-
Font-
-Name : <Application-defined or object-defined error> : Variant : Module1.Power_3Ph

Michael Bryant
Southern Ocean Software
 
If Power_3Ph is an UDF called by a cell formula then it can't make any change in the sheets.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yes it is a UDF called from a cell formula, so how can I make changes to the sheet. I even tried calling a sub from the function and that doesn't work either. Is there no way to do this at all?

Michael Bryant
Southern Ocean Software
 


A UDF can ONLY return a VALUE to the cell in which it is called. NOTHING ELSE.

If you want to make other changes to the sheet, you need to run a Sub directly. It cannot be called from the UDF.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
FYI, you already had the info at 27 Nov 08 4:26
 
PHV said:
If Power_3Ph is an UDF called by a cell formula then it can't make any change in the sheets.


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top