+ Reply to Thread
Results 1 to 4 of 4

Help with custom functions

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-30-2008
    Posts
    105

    Help with custom functions

    I have some custom functions in an excel spreadsheet that a couple people use for this particular template. I put these functions in the "Module" section. These functions work fine on my machine and another co-workers machine. We all use Excel 2003, but another co-worker, also on Excel 2003, will get the "#NAME" error whenever she tries to change the value of any of the cells that these functions use to calculate a value.

    Function div(cell As Variant) As Variant
        If IsEmpty(cell) Then
            div = ""
        Else
            div = cell / Range("$B$9")
        End If
        
    End Function
    
    Function pst(x As Variant) As Variant
        If IsEmpty(x) Then
            pst = ""
        Else
            pst = x
        End If
    End Function
    Function ifx(cellx As String) As String
        If Left(cellx, 2) = "'X" Or Left(cellx, 1) = "X" Then
            ifx = 1
        Else
            ifx = "N/A"
        End If
        
    End Function
    
    Function lf(rate As Variant, load As Variant, hour As Variant) As Double
        Const LoadFactorA = 2.151814912
        Const LoadFactorB = 1.930413331
        Const LoadFactorC = 1.585907751
        Const LoadFactorD = 1.423288683
        Const LoadFactorE = 1.2394746
        Const LoadFactor0 = 0
        
        If rate = "" Then
            rate = 0
        End If
        
        If hour = "" Then
            hour = 0
        End If
        
        
        Select Case load
            Case "A": lf = rate * LoadFactorA
            Case "B": lf = rate * LoadFactorB
            Case "C": lf = rate * LoadFactorC
            Case "D": lf = rate * LoadFactorD
            Case "E": lf = rate * LoadFactorE
            Case "": lf = rate * LoadFactor0
        End Select
        
        If hour > 200 And lf = rate * LoadFactorA Or lf = rate * LoadFactorB Then
            lf = lf * 200
        Else
            lf = lf * hour
        End If
    
            
    End Function
    Function prod(cost As Variant, factor As Variant) As Variant
        Const FactorF = 1.09601428571429
        Const FactorG = 1.175
        Const Factor0 = 0
        
        If cost = "" Then
            cost = 0
        End If
        
        Select Case factor
            Case "F": prod = cost * FactorF
            Case "G": prod = cost * FactorG
            Case "": prod = cost * Factor0
        End Select
    End Function
    Function divide(x As Variant, y As Variant) As Variant
        If y = 0 Then
            divide = 0
        Else
            divide = x / y
        End If
    End Function
    I haven't the slightest clue as to why it'd do this especially since it works fine for myself and my co-worker.

  2. #2
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    My guess is that her macro security settings are set to High, which would disable the macros, and therefore cause the error.

    HTH

    Jason

  3. #3
    Forum Contributor
    Join Date
    04-30-2008
    Posts
    105
    Quote Originally Posted by jasoncw
    My guess is that her macro security settings are set to High, which would disable the macros, and therefore cause the error.

    HTH

    Jason
    Would that cause the formulas to show an error message as soon as she opens the file?

    Nevermind, just tried it for myself. thanks a bunch! I was really stumped for a second. Glad its an easy fix.

  4. #4
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    No, the values would be preserved, but the first time she attempts to edit the cell, it will give the #NAME! error.

    You can verify this by disabling macros when you open the file and see what happens.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1