Counting Rows that hold a Defined Word in a Word Table
I am trying to count the Rows of a Word Table.
The table is made you of 2 Columns, others may have extra Columns, but this should not affect the Macro I'm trying to write and asking for help on.
I have created a Dummy Document to create the Marco in before I add it to my Main Document.
Here is the Dummy Data...
* Batteries not included.
10 things I hate about you.
13 Ghosts (The 1st version, 1959, Need a Blue & Red viewer as in 3D).
DOCVARIABLE VHS \# “#,##0” \* MERGEFORMAT
DOCVARIABLE DVD \# “#,##0” \* MERGEFORMAT
DOCVARIABLE BRD \# “#,##0” \* MERGEFORMAT
Total Videoed to Keep:
DOCVARIABLE V2K \# “#,##0” \* MERGEFORMAT
There is only 1 Table in the Word Document, This one is only 2 Columns, others my have more, but that wont have anything to do with this Macro.
What I wish to do is Count the Rows of the table that has the Word "VHS." in Column 1.
Then Count the Rows that has the Word "DVD.", then "BRD.", then to add these three together, then take that total off the Total number of Rows of the Table.
I then would like to place the answers into the TextFields as shown under the Table above?
The layout of the TextFields may change in time, and maybe even put into the "Footer".
Here is the Macro I've created, but cannot workout why it is not working...
'Count Number of Films/Series I Have
Dim WhichRow As Long
Dim WhichTable As Long
Dim VHS As Long
Dim DVD As Long
Dim BRD As Long
Dim V2K As Long
VHS = 0
DVD = 0
BRD = 0
V2K = 0
StatusBar = "Please Wait... Getting Totals..."
For WhichRow = 1 To .Rows.Count
'Working Out the Total Number of Original Video Tapes
If .Cell(WhichRow, 1).Range.Text = "VHS." Then
VHS = VHS + 1
'Working Out the Total Number of Original DVDs
If .Cell(WhichRow, 1).Range.Text = "DVD." Then
DVD = DVD + 1
''Working Out the Total Number of Video Tapes that I have Recorded
If .Cell(WhichRow, 1).Range.Text = "BRD." Then
BRD = BRD + 1
.Variables("VHS").Value = VHS
.Variables("DVD").Value = DVD
.Variables("BRD").Value = BRD
.Variables("V2K").Value = .Tables(1).Rows.Count - (VHS + DVD + BRD)
'Only Needed for Testing...
Testing = MsgBox(" Total VHS's: " & VHS & vbLf _
& " Total DVD 's: " & DVD & vbLf _
& " Total BRD 's: " & BRD & vbLf _
& "===================" & vbLf _
& "Total Videoed to Keep: " & V2K, vbOKOnly, "Testing...")
StatusBar = ""
Any help or advice will be a great help.
Anwsers to the Problem Counting Rows that hold a Defined Word in a Word Table
I didn't really look at your code, but something like this should work:
'A basic Word macro coded by Greg Maxey
Dim lngRows As Long, lngDVD As Long, lngVHS As Long, lngBRD As Long
Dim lngIndex As Long
Dim oTbl As Word.Table
Dim oCell As Word.Cell
Set oTbl = ActiveDocument.Tables(1)
lngRows = oTbl.Rows.Count
For lngIndex = 1 To lngRows
If InStr(oTbl.Cell(lngIndex, 1).Range.Text, "DVD") > 0 Then lngDVD = lngDVD + 1
If InStr(oTbl.Cell(lngIndex, 1).Range.Text, "VHS") > 0 Then lngVHS = lngVHS + 1
If InStr(oTbl.Cell(lngIndex, 1).Range.Text, "BRD") > 0 Then lngBRD = lngBRD + 1
.Variables("DVD").Value = lngDVD
.Variables("VHS").Value = lngVHS
.Variables("BRD").Value = lngBRD
.Variables("V2K").Value = lngRows - (lngDVD + lngVHS + lngBRD)
I went back and looked at your code. Your main problem is in lines like this:
If .Cell(WhichRow, 1).Range.Text = "VHS." Then
Cell text includes the end of cell marker which has a length value = 2
So change to:
If Left(.Cell(WhichRow, 1).Range.Text, Len(.Cell(WhichRow, 1).Range.Text) - 2) = "VHS." Then
Running System Update Readiness Command
On running the System Update readiness Command, it will Detect & Replace Incorrect Registry data with the Correct one. Which may ultimately Solve Counting Rows that hold a Defined Word in a Word Table in Windows.
- Open CMD as Administrator by Simply Right Clicking on Start button > Command Prompt (Admin).
- Now Type or Copy paste "DISM.exe /Online /Cleanup-image /Scanhealth" and hit Enter,
- Now again Type or Copy paste this "DISM.exe /Online /Cleanup-image /Restorehealth" and hit Enter.
- Close the Command Prompt Window because we are done.
Reboot your Windows & see if error Counting Rows that hold a Defined Word in a Word Table still comes up.
Note: Your administrator's password might be needed.
Recommended Method to Repair the Problem: Counting Rows that hold a Defined Word in a Word Table:
How to Fix Counting Rows that hold a Defined Word in a Word Table with SmartPCFixer?
1. You can Download Error Fixer here. Install it on your system. When you open it, it will perform a scan.
2. After the scan is done, you can see the errors and problems which need to be repaired.
3. The Repair part is done, the speed of your computer will be much higher than before and the errors have been removed. You can also use other functions in SmartPCFixer. Like dll downloading, windows updating and print spooler error repair.
Related: How Can You Update & Download NVidia 6100, 6800 GS/XT Display Driver v.260.89 WHQL,Where to Download NVidia GeForce 8800 GT WHQL-certified driver v.196.21,How to Update & Download NVidia GeForce Go 7400 Display Driver v.260.19.12,[Solved] Download NVidia GeForce GTX 460M Driver v.331.82,Download NVidia Quadro Plex Model IV VGA Driver v.304.43 Certified,Way to Download RealTek RTL8100C(L) Driver v.5.01,Way to Download RealTek RTL8100E Drivers v.694,Way to Update & Download RealTek RTL8101L Auto Installation Program v.6.110 driver,Method to Update & Download RealTek RTL8111G PXE and RPL ROM code v.2.58 driver,How to Update & Download RealTek RTL8411B(N) Driver v.10.003,Best Way to Update & Download ASUS A53SV nVidia Graphics Driver v.18.104.22.16886,Method to Herunterladen ASUS K75VJ Intel Rapid Storage Technology Treiber v.22.214.171.1240,How Can You Update & Download ASUS CG8580 Intel Chipset Driver v.126.96.36.1999,Method to Update & Download ASUS K41VD Intel INF Update Driver v.188.8.131.525,Way to Update & Download ASUS Pro70T NB Probe v.3.0.0026 driver
Read More: How to Fix - Control Panel\All Control Panel Items\Personalisation?,Fast Solution to Error: Copied cells only remain selected for ~2 seconds,How Can I Fix - control panel power options?,[Solved] Convert Word to Pdf in microsoft office 2007 for Free without software,How to Fix Error - Connection to Internet Explorer has ended before I decide?,Closing Internet Explorer causes error,Compare 2 Tables and Calculate the PROFIT Faster,Computer goes to Windows Boot Manager after Start,Connect to one of my network computer remotely when don't allow exception box Marked,computer locking up randomly