Consulting

Results 1 to 3 of 3

Thread: Solved: Using VLOOKUP in VBA Code

  1. #1
    VBAX Contributor Glaswegian's Avatar
    Joined
    Sep 2004
    Location
    Glasgow, Scotland
    Posts
    196
    Location

    Solved: Using VLOOKUP in VBA Code

    Hi again

    I have 2 workbooks. One contains a list of Managers and their assigned code numbers. The other is received monthly and contains data relating to monthly performance. In many cases, the monthly data contains the correct Manager code but not the Manager name. The Manager name needs to be populated.

    Most of my code works fine. Using the Manager list, I can open the relevant monthly workbook etc, but I can't seem to get my Vlookup to work.

    The Manager name appears in Column F and the code appears in Column E, both in the Monthly Data workbook. In the Manager code workbook, the list is a named range called MainList. This list can be added to or deleted from and I have code running that sorts and renames the table.

    The problem, I think , is in referencing the named range in the Manager code workbook.
    Set wbkMonthly = Workbooks.Open(myPath & "Completion and Doc Fees" & " " & strMonth & ".xls")
    finalRow = wbkMonthly.ActiveSheet.Range("F65536").End(xlUp).Row
    For x = 2 To finalRow
        Cells(x, 6).Value = WorksheetFunction.VLookup(Range("F" & x), "MainList", 2, False)
    Next x
    The above code is run from a button on the Manager code workbook.

    Any help much appreciated.
    Iain - XL2010 on Windows 7

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try

    [vba]

    Cells(x, 6).Value = Application.VLookup(Range("F" & x), Range("'Manager.xls'!MainList"), 2, False)
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Contributor Glaswegian's Avatar
    Joined
    Sep 2004
    Location
    Glasgow, Scotland
    Posts
    196
    Location
    Thanks xld - sorted.

    Blasted quotation marks....
    Iain - XL2010 on Windows 7

Posting Permissions

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