Announcement

Collapse
No announcement yet.

VBA: FIND FIRST ROW

Collapse
This topic is closed.
X
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VBA: FIND FIRST ROW



    Hi,

    FINDING THE FIRST ROW FOR "KVV"

    When I do a filter to the Segment Code for "KVV" , the first row for "KVV" is Row 4.

    I have done a Marco to help me find the FIRST ROW of "KVV" but the marco will not go and find the FIRST ROW of "KVV" it will just find the Second Row.

    I want the marco help me find the first row of "KVV", that is Row 4.

    How am I going to do that??
    see attract file to have a clearer view.

    THANK YOU…

    Code:

    Sub Macro1()
    '

    '
    column1 = Range("A1").End(xlToRight).Column


    Range(Cells(1, 1), Cells(1, column1)).Select

    Selection.AutoFilter
    Selection.AutoFilter Field:=5, Criteria1:="KVV"


    'it will not offset to the fourth row of "KVV"
    'it will select two row, WHY?

    Cells(1, 5).Offset(1, 0).Select

    firstrow = ActiveCell.Row
    firstcolumn = ActiveCell.Column

    End Sub

  • #2
    Hi LTT

    Have a look at the attached file. It uses the Find method to get what you want.

    See if does what you want.

    A few tips for your variable names. Always Dim all your variables. Instead of firstrow use FirstRow this then allows you ensure that Excel has recognised the variable if you type it in lower case Excel wil change it to uppercase.

    HTH

    Sub FindKVV()
    '
    ' FindKVV Macro
    ' Macro recorded 01-10-2003 by Neale Blackwood
    '

    Dim FirstRow
    Dim FirstColumn

    Columns("E:E").Select
    Selection.Find(What:="KVV", After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False).Activate

    FirstRow = ActiveCell.Row
    FirstColumn = ActiveCell.Column
    MsgBox "The Row is " & FirstRow & " the column number is " & FirstColumn

    End Sub
    There are three types of people in this world.
    Those who can count and those who can't.

    Comment


    • #3
      Hi LTT, Neale,

      I am not sure this will help but the 'Match' function will identify the row number of an array when seeking a particular string.

      Does this help?

      GrahamB
      But I always say luck is where preparation meets opportunity (Justin Langer 23/11/01)

      Comment


      • #4


        hi Neale, GrahamB

        Thank you Neale and thanks for your advice about Dim all the variables.

        thank You GrahamB... your method can help me identify the row number... thanks

        Comment

        Working...
        X