Results 1 to 11 of 11

Creating a FUNCTION that "looksup" data from an EXTERNAL workbook...I'm failing, HELP!

Threaded View

  1. #1
    Registered User
    Join Date
    06-22-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Creating a FUNCTION that "looksup" data from an EXTERNAL workbook...I'm failing, HELP!

    My FUNCTION takes person's UID and returns Dept from an external spreadsheet.
    When I try to debug my function with F8, it just quits working (as a function- F8 debug worked as a sub). Any help would be great. By the way, here's some of the specific challenges I've run into:

    * What I think I'm doing seems like it SHOULD be a common idea!
    * I want to hardcode the whole path into the function.
    * I tried moving the "sub" into the function, but that didn't work...then I tried calling the sub from the function (like below), but that doesn't work either
    * I will write 2 or 3 functions like Get_Dept (Get_section, Get_Name) that will just return different column data form the directory workbook

    Feel free to give me a suggestion from scratch! But, here's what I've got so far:

    Public uid As String
    Public dept As String
    
    Public Sub getData(uid, dept As String)
    Dim wBook As Workbook
    Dim Dir_MRange As String
    Dim DirectoryRange As Variant
    ActiveWB = ActiveWorkbook.Name 'This workbook
    Set wBook = Workbooks.Open("C:\Users\myuser\Documents\REFERENCE\SAP\My Directory 05-2012.xlsx") ' Path to external
    Dir_MRange = "B2:B14740" 'This contains the UID to match from
    uidrow = Application.WorksheetFunction.Match(uid, wBook.Worksheets("Directory").Range(Dir_MRange), 0)
    dept = wBook.Worksheets("Directory").Range("I" & uidrow + 1).Offset(0, 0).Value 'The column of data to return is column "I"
    wBook.Close
    Set wBook = Nothing
    End Sub
    Public Function Get_Dept(uid_local As String)
    dept = "empty"
    uid = uid_local
    Call getData(uid, dept)
    Get_Dept = dept
    End Function

    Any help would be GREATLY appreciated!
    Last edited by insaneoctane; 06-25-2012 at 02:48 AM. Reason: add code tags, remove extraneous info

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