+ Reply to Thread
Results 1 to 4 of 4

select a cell following vlookup

  1. #1
    caroline
    Guest

    select a cell following vlookup

    I am trying to find a value and then select the cell found.
    the following does not work because of "range(res).select"
    any idea? Thanks
    (I am not using the Find function because the range "table" includes
    functions)

    Dim res As Variant
    Dim table As Range
    Dim myVal As Range
    Set myVal = Range("LastQTR")
    Set table = Range("table")

    res = Application.HLookup(myVal, table, 2, False)
    If IsError(res) Then
    MsgBox "not found"
    Else
    range(res).select

    End If
    --
    caroline

  2. #2
    Bob Umlas, Excel MVP
    Guest

    RE: select a cell following vlookup

    res will be a value, like 36, or "BOB", not a range object, so
    Range(res).Select doesn't work. You can do this:
    On Error Resume Next
    res = Application.HLookup(MyVal, table, 2, False)
    Set ans = table.Offset(1).Resize(1, table.Columns.Count).Find(res)
    If Err.Number <> 0 then
    Msgbox "Not Found"
    Else
    ans.Select
    End If

    "caroline" wrote:

    > I am trying to find a value and then select the cell found.
    > the following does not work because of "range(res).select"
    > any idea? Thanks
    > (I am not using the Find function because the range "table" includes
    > functions)
    >
    > Dim res As Variant
    > Dim table As Range
    > Dim myVal As Range
    > Set myVal = Range("LastQTR")
    > Set table = Range("table")
    >
    > res = Application.HLookup(myVal, table, 2, False)
    > If IsError(res) Then
    > MsgBox "not found"
    > Else
    > range(res).select
    >
    > End If
    > --
    > caroline


  3. #3
    Tom Ogilvy
    Guest

    RE: select a cell following vlookup


    Dim res As Variant, res1 as Variant
    Dim table As Range
    Dim myVal As Range
    Set myVal = Range("LastQTR")
    Set table = Range("table")

    'res = Application.HLookup(myVal, table, 2, False)
    res1 = Application.Match(myVal,Table.Rows(1),False)
    If IsError(res1) Then
    MsgBox "not found"
    Else
    Table(1).Cells(2,res1).select
    End If

    --
    Regards,
    Tom Ogilvy

    "caroline" wrote:

    > I am trying to find a value and then select the cell found.
    > the following does not work because of "range(res).select"
    > any idea? Thanks
    > (I am not using the Find function because the range "table" includes
    > functions)
    >
    > Dim res As Variant
    > Dim table As Range
    > Dim myVal As Range
    > Set myVal = Range("LastQTR")
    > Set table = Range("table")
    >
    > res = Application.HLookup(myVal, table, 2, False)
    > If IsError(res) Then
    > MsgBox "not found"
    > Else
    > range(res).select
    >
    > End If
    > --
    > caroline


  4. #4
    caroline
    Guest

    RE: select a cell following vlookup

    Thanks a lot to both of you. it works
    --
    caroline


    "Tom Ogilvy" wrote:

    >
    > Dim res As Variant, res1 as Variant
    > Dim table As Range
    > Dim myVal As Range
    > Set myVal = Range("LastQTR")
    > Set table = Range("table")
    >
    > 'res = Application.HLookup(myVal, table, 2, False)
    > res1 = Application.Match(myVal,Table.Rows(1),False)
    > If IsError(res1) Then
    > MsgBox "not found"
    > Else
    > Table(1).Cells(2,res1).select
    > End If
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    > "caroline" wrote:
    >
    > > I am trying to find a value and then select the cell found.
    > > the following does not work because of "range(res).select"
    > > any idea? Thanks
    > > (I am not using the Find function because the range "table" includes
    > > functions)
    > >
    > > Dim res As Variant
    > > Dim table As Range
    > > Dim myVal As Range
    > > Set myVal = Range("LastQTR")
    > > Set table = Range("table")
    > >
    > > res = Application.HLookup(myVal, table, 2, False)
    > > If IsError(res) Then
    > > MsgBox "not found"
    > > Else
    > > range(res).select
    > >
    > > End If
    > > --
    > > caroline


+ Reply to Thread

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