Computer Forum Forum Index
Register  FAQ Profile Log in to check your private messages Log in Register 

Counting Text Occurrence In A Multi-row Range

 
Post new topic   Reply to topic    Computer Forum Forum Index -> microsoft word vba beginners
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Thu Nov 15, 2007 6:02 pm    Post subject: Counting Text Occurrence In A Multi-row Range Reply with quote

I've been working to find a solution to counting the cells in a Word
table that are in a multirow range, and have an "X" as text. (Table is
13 rows X 32 columns) Using the code below, I get a count of all of
the "X"s in rows 2 and 3. What I want to do is count the "X"s in the
range (in this case, 2, 31 thru 3, 2). Can someone please explain why
this code counts the complete rows, and give a possible solution?
TIA
Sub DoCount()
Dim tmpCount As Integer, CurrCol As Integer, CurrRow As Integer, MyStr
As String, MyRange As Range
tmpCount = 0
MyStr = "x"
Set MyTable = ActiveDocument.Tables(1)
Set MyRange = ActiveDocument.Range(Start:=MyTable.Cell(2,
31).Range.Start, _
End:=MyTable.Cell(3, 2).Range.End)
MyRange.Find.Execute FindText:=MyStr, Forward:=False
While MyRange.Find.Found = True
tmpCount = tmpCount + 1
MyRange.Find.Execute
Wend
MsgBox ("There are " & tmpCount & " finds")
End Sub
Back to top
Google
Sponsor





PostPosted: Thu Nov 15, 2007 6:02 pm    Post subject: Advertisement

Back to top
Display posts from previous:   
Post new topic   Reply to topic    Computer Forum Forum Index -> microsoft word vba beginners All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Computer Forum