Results 1 to 3 of 3
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    First occurence in column... (2000)

    Fast method to find first occunrence in Column A based my_var="Lombardia"... and last

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: First occurence in column... (2000)

    Try this:

    Dim my_var As String
    my_var = "Lombardia"
    Dim rngFirst As Range
    Dim rngLast As Range
    Set rngFirst = Range("A:A").Find(What:=my_var, LookIn:=xlValues, _
    LookAt:=xlWhole, SearchDirection:=xlNext)
    If rngFirst Is Nothing Then
    MsgBox "Not found"
    Else
    MsgBox "First occurrence found in " & rngFirst.Address
    End If
    Set rngLast = Range("A:A").Find(What:=my_var, LookIn:=xlValues, _
    LookAt:=xlWhole, SearchDirection:=xlPrevious)
    If rngLast Is Nothing Then
    MsgBox "Not found"
    Else
    MsgBox "Last occurrence found in " & rngLast.Address
    End If

  3. #3
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: First occurence in column... (2000)

    "SUPER" hANS.
    tKS.

Posting Permissions

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