+ Reply to Thread
Results 1 to 9 of 9

Thread: #NAME? Error

  1. #1
    Registered User
    Join Date
    08-19-2011
    Location
    coffs harbour, australia
    MS-Off Ver
    Excel 2010
    Posts
    12

    #NAME? Error

    Hi

    I am trying to get my spreadsheet to automatically calculate the pipes i am still required to order in of a specific diameter/class by taking the pipes i have on site then subtracting from them the pipes of a specific diameter/class to complete a section of pipeline then move onto the next section of pipeline and calculate it again however it returns #NAME? error

    Please help

    Many thanks

    Paul

    
    'Initiating function
    Function Pipes_Required(Pipe_Class As String, Pipes_On_Site As Integer) As Integer
        
        'define counter
        Dim i As Integer
        
        'while cell isnt blank
        While Worksheets("Pavement_Drainage_Data").Cells(i, 7) <> ""
        
            'If Pipe classes are the same
            If Pipe_Class = Worksheets("Pavement_Drainage_Data").Cells(i, 7) Then
                
                'minus pipes from delivered pipes
                 Pipes_Required = Pipes_Required - Pipes_On_Site
            
            'End if
            End If
        
        'Step counter
        i = i + 1
        
        'End while loop
        Wend
        
    'Return function
    End Function
    Attached Files Attached Files

  2. #2
    Forum Guru TMShucks's Avatar
    Join Date
    07-15-2010
    Location
    Manchester, England
    MS-Off Ver
    MSO 2003 & 2007
    Posts
    6,238

    Re: #NAME? Error

    i doesn't appear to be initialised so, the first time through, it will have a value of 0.

    Not sure if there are other problems.

    Best to post a sample workbook for an Excel problem ;-)

    Regards

  3. #3
    Registered User
    Join Date
    08-19-2011
    Location
    coffs harbour, australia
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: #NAME? Error

    Hi here is the workbook I am trying to run the function on

    Is it the function that's not initializing, how come what have I done wrong

    Cheers Paul
    Attached Files Attached Files

  4. #4
    Forum Guru TMShucks's Avatar
    Join Date
    07-15-2010
    Location
    Manchester, England
    MS-Off Ver
    MSO 2003 & 2007
    Posts
    6,238

    Re: #NAME? Error

    I don't really understand what your function is meant to be doing so I'm struggling to debug it.

    However, twp basic problems:

    1. as I said, you need to initialise the variable i. For example:

    Dim i As Integer: i = 1

    and:

    2. you cannot have the function name the same as the module name. I'd suggest you rename the module as something like mPipes_Required and the function as fPipes_Required, although the latter is not essential.


    Regards

  5. #5
    Registered User
    Join Date
    08-19-2011
    Location
    coffs harbour, australia
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: #NAME? Error

    Hi sorry for the vagueness I will try again. so now i have split it up int two functions one to sum the pipes required and then one to sum the pipes on site

    
    
    'Initiating function
    Function Pipes_Required(Pipe_Class As String) As Integer
        
        'define counter
        Dim i As Integer
        
        'while cell isnt blank
        While Worksheets("Pavement_Drainage_Data").Cells(i, "F") <> ""
        
            'If Pipe classes are the same
            If Pipe_Class = Worksheets("Pavement_Drainage_Data").Cells(i, "F") Then
                
                'minus pipes from delivered pipes
                 Pipes_Required = Pipes_Required - Worksheets("Pavement_Drainage_Data").Cells(i, "H")
            
            'End if
            End If
        
        'Step counter
        i = i + 1
        
        'End while loop
        Wend
        
    'Return function
    End Function
    is designed to step through the Pavement_Drainage_Data worksheet and sum up the number of pipes that share the same diameter and class as designated in Pipe_Class.

    ' Initialise Function
    Function Pipes_On_Site(Pipe_Class As String) As Double
        
        'Initilise i
        Dim i As Integer
        
        'set i
        i = 2
        
        'While rows are not blank
        While Workbooks("Drainage").Worksheets("General_Data").Cells(i, 6) <> ""
            
            'if pipe diameters and classes are equal
            If Workbooks("Drainage").Worksheets("General_Data").Cells(i, 11) = Pipe_Class And Workbooks("Drainage").Worksheets("General_Data").Cells(i, 7) = "z5000" Then
                
                'then add pipes to pipes on site
                Pipes_On_Site = Pipes_On_Site + Cells(i, 6)
            End If
            
            'step i
            i = i + 1
        
        Wend
    
    End Function
    is designed to step through a separate workbook with delivery data on it Workbooks("Drainage").Worksheets("General_Data") and sum up all the deliveries with the same diameter and class as designated in Pipe_Class and return them to this sheet. the idea is as this delivery spreadsheet is updated the pipes required data will stay the same and by subtracting the pipes delivered from the pipes required i will know how many are still to come in or that i have to order.

    Many thanks

    Paul

  6. #6
    Forum Guru TMShucks's Avatar
    Join Date
    07-15-2010
    Location
    Manchester, England
    MS-Off Ver
    MSO 2003 & 2007
    Posts
    6,238

    Re: #NAME? Error

    Have you made the changes I suggested? They will, at least, remove the #NAME error.

    They won't necessarily make the function work.

    Regards

  7. #7
    Registered User
    Join Date
    08-19-2011
    Location
    coffs harbour, australia
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: #NAME? Error

    Hi
    I think i did what you said however the error is still present please see attached screen dump to see if i have any errors
    Attached Files Attached Files

  8. #8
    Valued Forum Contributor
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    1,958

    Re: #NAME? Error

    As far as I can see that function must always return a negative value. You have a line of code to subtract pipes delivered from the required number, but you don't have any code which adds anything to the number of pipes required.

    You also don't set a starting values for fPipes_Required.

    Personally when coding functions I don't like using the function name as a working variable within the function. I'll create a new variable, initialise it, use it in the function and then assign its value to the function before I exit.

    Other than that the function looks OK. Have you tried setting a break point and stepping through the code?

  9. #9
    Registered User
    Join Date
    08-19-2011
    Location
    coffs harbour, australia
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: #NAME? Error

    Hi so I solved the name error, turns out my spreadsheet was blocking macros so enabled that and that solved the first problem. Now I am getting a Value error for the second function Pipes_On_Site code I think maybe its because I am using integer where as the numbers are too 2 decimal points, what initialization should I use.
    'Initialise Function
    Function fPipes_On_Site(Pipe_Class As String) As Integer
    
        
        'Initilise i
        Dim i As Integer: i = 2
          
        'While rows are not blank
        While Workbooks("Drainage").Worksheets("General_Data").Cells(i, "F") <> ""
            
            'if pipe diameters and classes are equal
            If Pipe_Class = Workbooks("Drainage").Worksheets("General_Data").Cells(i, "K") Then
            
                'then add pipes to pipes on site
                fPipes_On_Site = fPipes_On_Site + Workbooks("Drainage").Worksheets("General_Data").Cells(i, "F")
            
            'End if
            End If
            
        'Step counter
        i = i + 1
        
        Wend
    
    End Function

+ 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.2.0