Results 1 to 4 of 4

Thread: Vbscript: Find, FindNext, Count # rows where statement

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2010
    Location
    Brussels
    Posts
    26

    Vbscript: Find, FindNext, Count # rows where statement

    Hi,

    I have a vbscript that needs to search in an excel sheet to find a specific word (strSearch).
    Then, the script needs to know on which rownumber this word was find.
    And on top, the script needs to see how many times this word was found in the specified Range. And that last one gives problems

    Code:
    Dim strSearch, therightrow
    strSearch = InputBox("Search:") 
    
    Set objRange = objWorksheet.UsedRange
    therightrow = objRange.Find(strSearch).Row
    MsgBox therightrow
    With this code above, he msgboxes me the number of the row where the first match was found.

    But he's not going to the next match, so I'm looking for some loop through the range in a way I get the following data:
    how many rows are affected with that match
    the rownumbers of these rows.

    I've been trying lots of things already, like this (obviously wrong):
    Code:
    Do Until objRange.Find(strSearch).count <> strSearch 
    Loop
    Can someone help me?

    I'm using it in Internet Explorer.

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Oct 2010
    Location
    Brussels
    Posts
    26

    Re: Vbscript: Find, FindNext, Count # rows where statement

    Code:
    therightrow = objRange.Find(strSearch).Row
    Perhaps I should make an array somehow from this .Find .Row thing...
    And then iterate through the array
    But how...

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2010
    Location
    Brussels
    Posts
    26

    Re: Vbscript: Find, FindNext, Count # rows where statement

    Anyone?

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 2010
    Location
    Brussels
    Posts
    26

    Re: Vbscript: Find, FindNext, Count # rows where statement

    Finally got it running... was actually quite easy, but overlooked the InStr function and always tried with Find or Match techniques...


    Code:
    Dim strsearch, loopCount, myRow
    
    strsearch = InputBox("Search:")
    loopcount = 1
    
    Do while not IsEmpty(objRange.Cells(loopCount, 1).Value)
    Dim i
    
    For i = 1 To 5
    
    If Not InStr(1, objRange.Cells(loopCount, i).Value, strsearch, vbTextCompare) = 0 Then
    myRow = myRow & objRange.Cells(loopCount, i).Row &"comma separated"
    End If
    
    Next
    loopCount = loopCount + 1
    Loop
    msgbox myRow

    Anyway, thanks for the great help

Posting Permissions

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



Click Here to Expand Forum to Full Width