+ Reply to Thread
Results 1 to 4 of 4

Return Row Number?

Hybrid View

  1. #1
    Registered User
    Join Date
    11-28-2007
    Posts
    57

    Return Row Number?

    I'm trying to get the row number of a cell that was selected in a find.


    Example:

    
    Sub findRowNumber()
    '
    '
        Cells.Find(What:="104", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
            xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False) _
            .Activate
            
        ActiveCell.Select
            
        MsgBox (" The Row number of the selected cell is " & rw.Row)
        
            
    End Sub

    As always, Thanks for your help, Phil
    Last edited by VBA Noob; 01-22-2008 at 09:38 AM.
    Phil
    Technician
    City of Clinton, SC
    SCADA, GIS, Utility Billing, Networking
    I'm doing the best I can with the little bit I know.

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    To wrap code use / symbol not \

    Also No need to select

    Try

    Sub findRowNumber()
    Dim Rng As Range
        
    Set Rng = ActiveSheet.UsedRange.Find(What:="104", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
            xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext)
            
    MsgBox (" The Row number of the selected cell is " & Rng.Row)
        
            
    End Sub
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Forum Contributor stevebriz's Avatar
    Join Date
    09-07-2006
    Location
    Santiago Chile
    Posts
    389
    You can do something like below (this will find all cells with this value )

    Sub findRowNumber()
    Dim FND As Boolean
    FND = False
    With ActiveSheet.Cells
    '
    Set Rw = .Find(What:="104", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
    xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
    
    
        If Not Rw Is Nothing Then
        firstAddress = Rw.Address
            Do
            FND = True
                    Rw.Select
                MsgBox (" The Row number of the selected cell is " & Rw.Row)
                Set Rw = .FindNext(Rw)
            Loop While Not Rw Is Nothing And Rw.Address <> firstAddress
        End If
    
    
        If FND = False Then
        MsgBox (" No Cell Found with 104 value")
        End If
    End With
    End Sub
    VBA - The Power Behind the Grid

    Posting a sample of your workbook makes it easier to look at the Issue.

  4. #4
    Registered User
    Join Date
    11-28-2007
    Posts
    57
    Thanks, both of those helped!

+ 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