Results 1 to 3 of 3

Custom functions references to other files.

Threaded View

kemit Custom functions references... 09-12-2016, 05:10 AM
bakerman2 Re: Custom functions... 09-12-2016, 05:51 AM
kemit Re: Custom functions... 09-12-2016, 06:00 AM
  1. #1
    Registered User
    Join Date
    01-07-2014
    Location
    Port Elizabeth, South Africa
    MS-Off Ver
    Excel 2010
    Posts
    39

    Question Custom functions references to other files.

    Hi all, I have created a few "Public Functions" that are stored in a master control file ( a file whose name changes with each new version). These functions need to reference named ranges in various files, and I do not wish to "hard code" these file names into the function nor do I want to have too many arguments when entering the function on the spread sheet. How can I get the function code to automatically look up the required file name irrespective to which workbook is "active" at the time of recalculation?

    in the code below the file name is hardcoded in "MastFile" this works very well but I would like to remove the hardcoded statement so as to make the code more portable between different files.

    Please help.

    Public Function VehChoice(RouteType As String, MaxVol_1 As Double, Maxvol_2 As Double)
    
    'Calculates the type of vehicle required based on route type and the expected Max Vol on the route
    
        Dim Vol  As Double
        Dim Choice As String
        Dim Trunk6m As Double
        Dim Trunk9m As Double
        Dim Trunk12m As Double
        Dim Feeder6m As Double
        Dim Feeder9m As Double
        Dim Feeder12m As Double
        Dim MastFile As String
        
    'Set MastFile name
            MastFile = "Costing_model_BP_2032_V1_2.xlsm"     '    Worksheets("Parameters").Range("Mast_File").Value '  sets the name of the Master file.
    
    
    'Set the bus type values from the assumptions sheet
        Trunk6m = Workbooks(MastFile).Worksheets("Assumptions & Rates").Range("Choice_6m").Value
        Trunk9m = Workbooks(MastFile).Worksheets("Assumptions & Rates").Range("Choice_9LERH").Value
        Trunk12m = Workbooks(MastFile).Worksheets("Assumptions & Rates").Range("Choice_12LERH").Value
        Feeder6m = Workbooks(MastFile).Worksheets("Assumptions & Rates").Range("ChoiceF_6m").Value
        Feeder9m = Workbooks(MastFile).Worksheets("Assumptions & Rates").Range("ChoiceF_9m").Value
        Feeder12m = Workbooks(MastFile).Worksheets("Assumptions & Rates").Range("ChoiceF_12m").Value
    
    'Determine the maximum MaxVol value
        Vol = WorksheetFunction.Max(MaxVol_1, Maxvol_2)
        
    'Determine if route is Feeder or Trunk
    
        Select Case RouteType
            Case Is = "BRT - full dedicated lanes":
                Select Case Vol
                    Case Is <= Trunk6m: Choice = "6m"
                    Case Is <= Trunk9m: Choice = "9LERH"
                    Case Is <= Trunk12m: Choice = "12LERH"
                    Case Is > Trunk12m: Choice = "18LERH"
                End Select
            Case Is = "Feeder routes":
                Select Case Vol
                    Case Is <= Feeder6m: Choice = "6m"
                    Case Is <= Feeder9m: Choice = "9LERH"
                    Case Is <= Feeder12m: Choice = "12LERH"
                    Case Is > Feeder12m: Choice = "12LERH"
                End Select
        End Select
    
    VehChoice = Choice
    
    End Function
    Last edited by kemit; 09-12-2016 at 05:17 AM. Reason: added example code

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Need help with creating help files for custom VB excel 10 functions
    By DavidVentura in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-25-2013, 02:16 AM
  2. AddIn With custom functions - Functions not working in Excel2010
    By brum17 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-10-2011, 08:25 AM
  3. References in functions
    By jc_cfa in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-11-2009, 01:39 PM
  4. Custom tool tip for custom functions
    By usr789 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-24-2007, 02:09 PM
  5. [SOLVED] Custom functions or VBA functions for Avg, Std, Min, Max?
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-17-2006, 06:00 AM
  6. [SOLVED] Returning arrays from custom worksheet functions in xll files
    By JacksonRJones in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-22-2006, 01:50 PM
  7. Adding Help Files To Custom Functions/Macros
    By MDW in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-30-2006, 02:00 PM
  8. Using custom functions within custom validation
    By Neil in forum Excel General
    Replies: 4
    Last Post: 12-14-2005, 06:45 PM

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