+ Reply to Thread
Results 1 to 3 of 3

Offset

  1. #1
    Forum Contributor
    Join Date
    04-09-2005
    Location
    Multan. Pakistan
    Posts
    129

    Question Offset

    Hi Freinds,

    I have a Table with 2 Fields

    A B
    1000 ABC
    2000 DEF
    3000 GHI
    4000 JKL


    I want to Find "GHI" in col B and if found then shows the corresponding value of Col "A" i,e 3000.

    In simple the Formula is

    @offset(b1,match("GHI,b1:b4,0)-1,-1)

    I neet the code in VBA-Excel

    Thanks

    Syed Haider Ali

  2. #2
    Jim Thomlinson
    Guest

    RE: Offset

    This code assumes that you only want to find the first instacne of GHI but it
    is easily modified to find all of the instances if you need...

    Sub test()
    Call FindStuff("GHI")
    End Sub

    Public Sub FindStuff(ByVal ThingToFind As Variant)
    Dim wks As Worksheet
    Dim rngToSearch As Range
    Dim rngCurrent As Range

    Set wks = ActiveSheet
    Set rngToSearch = wks.Columns(2)
    Set rngCurrent = rngToSearch.Find(ThingToFind)
    If rngCurrent Is Nothing Then
    MsgBox ThingToFind & " was not found."
    Else
    MsgBox rngCurrent.Offset(0, -1).Value
    End If

    End Sub

    --
    HTH...

    Jim Thomlinson


    "Syed Haider Ali" wrote:

    >
    > Hi Freinds,
    >
    > I have a Table with 2 Fields
    >
    > A B
    > 1000 ABC
    > 2000 DEF
    > 3000 GHI
    > 4000 JKL
    >
    >
    > I want to Find "GHI" in col B and if found then shows the corresponding
    > value of Col "A" i,e 3000.
    >
    > In simple the Formula is
    >
    > @offset(b1,match("GHI,b1:b4,0)-1,-1)
    >
    > I neet the code in VBA-Excel
    >
    > Thanks
    >
    > Syed Haider Ali
    >
    >
    > --
    > Syed Haider Ali
    > ------------------------------------------------------------------------
    > Syed Haider Ali's Profile: http://www.excelforum.com/member.php...o&userid=21994
    > View this thread: http://www.excelforum.com/showthread...hreadid=400053
    >
    >


  3. #3
    JE McGimpsey
    Guest

    Re: Offset

    One way:

    Dim rFound As Range
    Set rFound = Range("B:B").Find( _
    What:="GHI", _
    LookIn:=xlValues, _
    LookAt:=xlWhole, _
    MatchCase:=False)
    If Not rFound Is Nothing Then _
    MsgBox rFound.Offset(0, -1)

    BTW - your XL formula would be a bit more efficient as

    =INDEX(A1:A4,MATCH("GHI",B1:B4,FALSE))



    In article
    <[email protected]>,
    Syed Haider Ali
    <[email protected]> wrote:

    > Hi Freinds,
    >
    > I have a Table with 2 Fields
    >
    > A B
    > 1000 ABC
    > 2000 DEF
    > 3000 GHI
    > 4000 JKL
    >
    >
    > I want to Find "GHI" in col B and if found then shows the corresponding
    > value of Col "A" i,e 3000.
    >
    > In simple the Formula is
    >
    > @offset(b1,match("GHI,b1:b4,0)-1,-1)
    >
    > I neet the code in VBA-Excel
    >
    > Thanks
    >
    > Syed Haider Ali


+ 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