Consulting

Results 1 to 5 of 5

Thread: Solved: VBA VLookup Problem (Excel '97)

  1. #1
    VBAX Tutor phendrena's Avatar
    Joined
    Oct 2008
    Location
    Huddersfield, UK
    Posts
    285
    Location

    Solved: VBA VLookup Problem (Excel '97)

    Hi there,

    I have the following code :-
    [vba]Private Sub sSupportRota()
    Dim dtDate As Date
    Dim dtToday As Date
    Dim intMonth As Integer
    Dim strRange As String
    Dim ws As Worksheet
    Set ws = Worksheets("Support")
    dtToday = Date
    dtDate = Now
    intMonth = DatePart("m", dtDate)
    Select Case intMonth
    Case 1: strRange = "JanSupport"
    Case 2: strRange = "FebSupport"
    Case 3: strRange = "MarSupport"
    Case 4: strRange = "AprSupport"
    Case 5: strRange = "MaySupport"
    Case 6: strRange = "JunSupport"
    Case 7: strRange = "JulSupport"
    Case 8: strRange = "AugSupport"
    Case 9: strRange = "SepSupport"
    Case 10: strRange = "OctSupport"
    Case 11: strRange = "NovSupport"
    Case 12: strRange = "DecSupport"
    End Select
    ws.Range("B44") = Application.WorksheetFunction.VLookup(dtToday, ws.Range(strRange), 2, False)
    End Sub[/vba]

    I am getting the following error :
    "Run-time error 1004
    Unable to get the VLookup property of the WorksheetFunction class"

    Would anyone please be able to advise where i am going wrong.

    Thanks,
    Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
    Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
    But thats nothing compared to the horrors that lurk beneath The Trap Door.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Dim your dates as long
    [VBA]
    Private Sub sSupportRota()
    Dim dtDate As Long
    Dim dtToday As Long

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Tutor phendrena's Avatar
    Joined
    Oct 2008
    Location
    Huddersfield, UK
    Posts
    285
    Location
    Hi,

    Thanks for the reply.
    I've just tried that and i'm still getting the same error.
    The dates on the worksheet are formatted as dd/mm/yyyy.
    I've tried to change them to a standard excel format with no success.
    Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
    Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
    But thats nothing compared to the horrors that lurk beneath The Trap Door.

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I'm using the same format. Here's my test file.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Tutor phendrena's Avatar
    Joined
    Oct 2008
    Location
    Huddersfield, UK
    Posts
    285
    Location
    Thanks.

    I now feel really daft, as i've also discovered i'm using the wrong names ranges - should 'rota' and not 'support'.
    Making the changes to the dates and the named ranges now produce the result i'm looking for!

    Cheers.
    Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
    Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
    But thats nothing compared to the horrors that lurk beneath The Trap Door.

Posting Permissions

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