Calculating word count

N

Ninad Pradhan

Hi,

I have a table containing 3R x 4C which is used to document an audit finding. The table structure is fixed. The table exists as many times as the number of findings, i.e. for each finding, I insert a new table with the above structure.

I want to count the words "High", "Medium", "Low" (w/o quotes) in all the tables with the above structure and they are color coded Red, Gold and Sea Green respectively and Bold. They are always placed in the 3rd row and 2 column.

Help appreciated.

TIA.

Ninad.


Submitted via EggHeadCafe - Software Developer Portal of Choice
Database Design for Mere Mortals
http://www.eggheadcafe.com/tutorial...1f-1ced9909759c/database-design-for-mere.aspx
 
J

Jay Freedman

One method is to look at the text in cell (3,2) of each table and determine
whether it contains any of the three words. The following macro does that.
It ignores the formatting (color and bold), so if that's important then the
macro would have to be modified.

Sub CountLevels()
Dim HCount As Integer, MCount As Integer, LCount As Integer
Dim oTbl As Table
Dim strCellText As String, strResult As String

For Each oTbl In ActiveDocument.Tables
strCellText = oTbl.Cell(Row:=3, Column:=2).Range.Text

If InStr(strCellText, "High") Then
HCount = HCount + 1
End If

If InStr(strCellText, "Medium") Then
MCount = MCount + 1
End If

If InStr(strCellText, "Low") Then
LCount = LCount + 1
End If
Next

strResult = "High occurs " & HCount & " times" & vbCr
strResult = strResult & "Medium occurs " & MCount & " times" & vbCr
strResult = strResult & "Low occurs " & LCount & " times"
MsgBox strResult
End Sub

Another approach would be to modify the macro in
http://www.word.mvps.org/FAQs/MacrosVBA/NoTimesTextInDoc.htm. You 'd have to
do three separate searches, one for each of the words "High", "Medium",
"Low".

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
N

Ninad Pradhan

I'll try this out and this should help a lot of our auditors.



Jay Freedman wrote:

One method is to look at the text in cell (3,2) of each table and
28-Jan-10

One method is to look at the text in cell (3,2) of each table and determine
whether it contains any of the three words. The following macro does that.
It ignores the formatting (color and bold), so if that is important then the
macro would have to be modified.

Sub CountLevels()
Dim HCount As Integer, MCount As Integer, LCount As Integer
Dim oTbl As Table
Dim strCellText As String, strResult As String

For Each oTbl In ActiveDocument.Tables
strCellText = oTbl.Cell(Row:=3, Column:=2).Range.Text

If InStr(strCellText, "High") Then
HCount = HCount + 1
End If

If InStr(strCellText, "Medium") Then
MCount = MCount + 1
End If

If InStr(strCellText, "Low") Then
LCount = LCount + 1
End If
Next

strResult = "High occurs " & HCount & " times" & vbCr
strResult = strResult & "Medium occurs " & MCount & " times" & vbCr
strResult = strResult & "Low occurs " & LCount & " times"
MsgBox strResult
End Sub

Another approach would be to modify the macro in
http://www.word.mvps.org/FAQs/MacrosVBA/NoTimesTextInDoc.htm. You 'd have to
do three separate searches, one for each of the words "High", "Medium",
"Low".

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Ninad Pradhan wrote:

Previous Posts In This Thread:


Submitted via EggHeadCafe - Software Developer Portal of Choice
Realtime Stock Quote Tray Icon Balloon Tip App
http://www.eggheadcafe.com/tutorial...9-5edfb474aad4/realtime-stock-quote-tray.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top