Consulting

Results 1 to 4 of 4

Thread: Someone can help me out with writing a simple function??

  1. #1
    VBAX Newbie
    Joined
    Feb 2008
    Posts
    4
    Location

    Someone can help me out with writing a simple function??

    Hi folks~

    I just started taking a vba class so I have a minimal knowledge on function writing.

    Can someone help me to write function that has the following macro functions?

    =HLOOKUP(lookup_value, table_array, MATCH(lookup_value, lookup_array, [match type]), [range_lookup])


    I use this a lot but it is too messy if I have to put these same function more than two in just one cell.

    Thanks!!

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

    [vba]

    Function MyLookup(lookup_value, hlookup_array, match_array)
    Dim match_index As Long
    Dim hlookup_index As Long
    Dim cell As Range

    Set cell = match_array.Find(lookup_value)
    match_index = cell.Row - match_array.Cells(1, 1).Row + 1
    Set cell = hlookup_array.Rows(1).Find(lookup_value)
    hlookup_index = cell.Column - hlookup_array.Cells(1, 1).Column + 1
    MyLookup = hlookup_array.Cells(match_index, hlookup_index).Value

    End Function
    [/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 Newbie
    Joined
    Feb 2008
    Posts
    4
    Location

    Wow thanks but the problem is that..

    lookup value for hlookup and lookup value for match are different~~~




    Quote Originally Posted by xld
    For all matches

    [vba]

    Function MyLookup(lookup_value, hlookup_array, match_array)
    Dim match_index As Long
    Dim hlookup_index As Long
    Dim cell As Range

    Set cell = match_array.Find(lookup_value)
    match_index = cell.Row - match_array.Cells(1, 1).Row + 1
    Set cell = hlookup_array.Rows(1).Find(lookup_value)
    hlookup_index = cell.Column - hlookup_array.Cells(1, 1).Column + 1
    MyLookup = hlookup_array.Cells(match_index, hlookup_index).Value

    End Function
    [/vba]

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

    [vba]

    Function MyLookup(hlookup_value, hlookup_array, match_value, match_array)
    Dim match_index As Long
    Dim hlookup_index As Long
    Dim cell As Range

    Set cell = match_array.Find(match_value)
    match_index = cell.Row - match_array.Cells(1, 1).Row + 1
    Set cell = hlookup_array.Rows(1).Find(hlookup_value)
    hlookup_index = cell.Column - hlookup_array.Cells(1, 1).Column + 1
    MyLookup = hlookup_array.Cells(match_index, hlookup_index).Value

    End Function
    [/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

Posting Permissions

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