Microsoft Office Forums Looking for a macro for word count in one specific column of table, only rows with white background

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-16-2019, 03:02 AM
mobj mobj is offline Looking for a macro for word count in one specific column of table, only rows with white background Windows 10 Looking for a macro for word count in one specific column of table, only rows with white background Office 2019
Novice
Looking for a macro for word count in one specific column of table, only rows with white background
 
Join Date: Oct 2019
Posts: 2
mobj is on a distinguished road
Default Looking for a macro for word count in one specific column of table, only rows with white background

Hi all, new to these forums, and hoping someone can assist with the above if its not too complicated



I have a bit of a dilemma - I have been doing a long-term copy-editing project, in which I am required to review translated English in one column of a table - however, only the cells in that column which have a white background.

I have done hundreds of these documents, however it now turns out that the client may have made a mistake on the word counts of some of the documents, affecting the calculation of pay!

As I am paid per word, I am looking to try to find a quick and effective way to find the word count for each document (rather than tediously ctrl + selecting each cell which meets the criteria, and then running word count - super time consuming!)


The macro would need to be able to calculate word count in a given column for all rows which have a white / no background, and nothing else (i.e. ignoring grey/green background text). Ideally, it would be as automated as possible, perhaps even outputting the word count to a file or copying to clipboard. However even if I have to select the given column for each document and then run the macro, that would save me hours and hours of time.

I have attached a screenshot of a sample document that I need to do the word check for - only the text in the white background cells would be calculated.

Any suggestions or advice would be very much appreciated.

Cheers
John
Attached Images
File Type: png sample doc.png (92.5 KB, 8 views)
Reply With Quote
  #2  
Old 10-16-2019, 05:03 AM
gmaxey gmaxey is offline Looking for a macro for word count in one specific column of table, only rows with white background Windows 10 Looking for a macro for word count in one specific column of table, only rows with white background Office 2016
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 966
gmaxey will become famous soon enoughgmaxey will become famous soon enough
Default

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim lngCount
Dim oCell As Cell
Dim oRng As Range
  For Each oCell In Selection.Tables(1).Range.Cells
    If oCell.Range.Information(wdEndOfRangeColumnNumber) = 2 Then 'or whatever column index you need
      If oCell.Shading.BackgroundPatternColor = wdColorAutomatic Then
        Set oRng = oCell.Range
        oRng.End = oRng.End - 1
        lngCount = lngCount + oRng.ComputeStatistics(wdStatisticWords)
      End If
    End If
  Next
  MsgBox lngCount
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 10-17-2019, 03:09 AM
mobj mobj is offline Looking for a macro for word count in one specific column of table, only rows with white background Windows 10 Looking for a macro for word count in one specific column of table, only rows with white background Office 2019
Novice
Looking for a macro for word count in one specific column of table, only rows with white background
 
Join Date: Oct 2019
Posts: 2
mobj is on a distinguished road
Default

Quote:
Originally Posted by gmaxey View Post
Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim lngCount
Dim oCell As Cell
Dim oRng As Range
  For Each oCell In Selection.Tables(1).Range.Cells
    If oCell.Range.Information(wdEndOfRangeColumnNumber) = 2 Then 'or whatever column index you need
      If oCell.Shading.BackgroundPatternColor = wdColorAutomatic Then
        Set oRng = oCell.Range
        oRng.End = oRng.End - 1
        lngCount = lngCount + oRng.ComputeStatistics(wdStatisticWords)
      End If
    End If
  Next
  MsgBox lngCount
lbl_Exit:
  Exit Sub
End Sub

Wow, thank you so much! Works like a charm - I simply chose the right column number, and now click on the table, shortcut key the macro, and type the word count into an excel spreadsheet. What used to take me almost 1 minute per document now takes 5 seconds. Thank you!!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking for a macro for word count in one specific column of table, only rows with white background Macro to delete table rows based on the absence of a single specific keyword JellehFishh Word VBA 2 06-27-2019 08:23 AM
Looking for a macro for word count in one specific column of table, only rows with white background Macro delete table rows if cell in first column = $ Btop Word VBA 7 02-13-2018 05:36 PM
Looking for a macro for word count in one specific column of table, only rows with white background Macro Help Needed - White Background & PDF PJinNH Word VBA 3 05-04-2017 04:58 PM
Looking for a macro for word count in one specific column of table, only rows with white background Count # of times "text" is in 1 column is specific date is in the other column ann.acornacchio Excel 4 12-31-2016 05:40 PM
Copying specific columns of a table to WORD and deleting rows ffinley Word VBA 5 12-07-2015 04:01 PM


All times are GMT -7. The time now is 11:03 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft