|
-
Jan 28th, 2011, 06:27 AM
#1
Thread Starter
Junior Member
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.
-
Jan 28th, 2011, 09:30 AM
#2
Thread Starter
Junior Member
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...
-
Jan 30th, 2011, 04:52 AM
#3
Thread Starter
Junior Member
Re: Vbscript: Find, FindNext, Count # rows where statement
-
Jan 31st, 2011, 02:56 PM
#4
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|