Consulting

Results 1 to 3 of 3

Thread: Quick table lookup

  1. #1

    Quick table lookup

    Hi Everyone,

    I just need a quick bit of code that opens a workbook takes the current date and works out what the coressponding week number would be. If someone could help me out it will be more than appreciated.

    Lookup table looks like the following

    Week - Friday - Max - Min
    WK49_10 - 10Nov10 - 16NOV10 - 10NOV10

    So if the current date is the 14th december the VBA would use this table to return a string variable that equals Wk49_10

    Thank you in advance

    Ross

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

    [vba]

    Sub MatchDate()
    Dim wb As Workbook
    Dim MatchRow As Long

    Set wb = Workbooks.Open("C:\somedirectory\somefile.xls")
    On Error Resume Next
    MatchRow = Application.Match(CLng(Date), wb.Worksheets(1).Columns(2), 0)
    If MatchRow > 0 Then

    MsgBox wb.Worksheets(1).Cells(MatchRow, "A")
    End If

    End Sub
    [/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
    Thanks, Works perfectly!

Posting Permissions

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