+ Reply to Thread
Results 1 to 6 of 6

Finding several occurrences of a text in a column using FindNext

Hybrid View

  1. #1
    Registered User
    Join Date
    10-07-2011
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    68

    Finding several occurrences of a text in a column using FindNext

    Hello,
    I'm trying to find several occurrences of a text ("Yes") in a column as I would need the row values for each occurence. I'm using FindNext but the first occurrence is getting repeated. Could anyone help me to let only one istance of the occurence of "Yes" in col. G. Below are the code and the file.

    Sub findtest()
    
    Worksheets("ValueArea").Select
    Dim rngFound As Range
    Set rngFound = Range("G:G").Find(What:="Yes", LookIn:=xlValues, LookAt:=xlWhole)
    If Not rngFound Is Nothing Then
        firstaddress = rngFound.Address
        MsgBox firstaddress
    
    
    Do
        Set rngFound = Range("G:G").FindNext(rngFound)
        MsgBox rngFound.Address
        Loop Until rngFound.Address = firstaddress
    
    End If
    
    End Sub


    Thanks in advance.
    Attached Files Attached Files
    Last edited by realdemigod; 10-23-2016 at 07:56 AM.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Finding several occurrences of a text in a column using FindNext

    Sub findtest()
    
    Dim rngFound As Range
    
    With Worksheets("ValueArea").Columns("G")
        Set rngFound = .Find(What:="Yes", LookIn:=xlValues, LookAt:=xlWhole)
        If Not rngFound Is Nothing Then
            firstaddress = rngFound.Address
            MsgBox firstaddress
        
        
           Do
            Set rngFound = .FindNext(rngFound)
            MsgBox rngFound.Address
          Loop While rngFound.Address <> firstaddress
         ' Loop Until rngFound.Address = firstaddress
        
        End If
     End With
    End Sub

  3. #3
    Registered User
    Join Date
    10-07-2011
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    68

    Re: Finding several occurrences of a text in a column using FindNext

    Hello AB33,
    Thanks for your reply. I tried your code. $G$2 is still getting repeated.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Finding several occurrences of a text in a column using FindNext

    I do not know what you are expected from the find function. I have included a color to show you it picks up all matches.

    Sub findtest()
    
    Dim rngFound As Range
    
    With Worksheets("ValueArea").Columns("G")
        Set rngFound = .Find(What:="Yes", LookIn:=xlValues, LookAt:=xlWhole)
        If Not rngFound Is Nothing Then
            FirstAddress = rngFound.Address
    
           Do
               MsgBox FirstAddress
               rngFound.Interior.ColorIndex = 3
            Set rngFound = .FindNext(rngFound)
            MsgBox rngFound.Address
          Loop While rngFound.Address <> FirstAddress
         ' Loop Until rngFound.Address = firstaddress
        
        End If
     End With
    End Sub
    Sub findheaderhead()
    Dim rng As Range, cel, ws As Worksheet, FirstAddress As String
    
    
                 With Sheets("ValueArea").Columns(7)
                      Set rng = .Find("Yes", .Cells(.Cells.Count), xlValues, xlWhole)
                            If Not rng Is Nothing Then
                              FirstAddress = rng.Address
                               Do
                               rng.Interior.ColorIndex = 3
                                
                                Set rng = .FindNext(rng)
                              Loop While Not rng Is Nothing And rng.Address <> FirstAddress
                            End If
                 End With
         
             
    Set rng = Nothing
    Application.ScreenUpdating = True
    End Sub

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: Finding several occurrences of a text in a column using FindNext

    Should be like this
    Worksheets("ValueArea").Select
    Dim rngFound As Range
    Set rngFound = Range("G:G").Find(What:="Yes", LookIn:=xlValues, LookAt:=xlWhole)
    If Not rngFound Is Nothing Then
        firstaddress = rngFound.Address
    
    Do
        MsgBox rngFound.Address
        Set rngFound = Range("G:G").FindNext(rngFound)
        Loop Until rngFound.Address = firstaddress
    
    End If
    
    End Sub

  6. #6
    Registered User
    Join Date
    10-07-2011
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    68

    Re: Finding several occurrences of a text in a column using FindNext

    Thanks AB33 for trying

    Hello jindon, thank you very much!. Yes that is what I was looking for .

    Sorry I'm unable to give you any reputation points

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Counting the number of occurrences of specific text in a column
    By oneeasygeezer in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-23-2015, 11:11 AM
  2. [SOLVED] Counting text occurrences in a column
    By KaiserD2 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 08-17-2014, 09:13 AM
  3. [SOLVED] Use Countif and ?? to count occurrences of text string in a column
    By CWatsonJr in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-23-2014, 03:08 PM
  4. Finding multiple occurrences in a string
    By Julie_Heyes in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 11-01-2012, 03:27 PM
  5. Finding all occurrences of a pattern within a column
    By matcapir in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 10-05-2011, 11:16 AM
  6. Finding # of Occurrences in various cells.
    By The Exceller in forum Excel General
    Replies: 6
    Last Post: 08-13-2010, 10:02 AM
  7. find value in column with FindNext
    By nono in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-10-2010, 04:35 PM

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