A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Counting non-blank cells in a column



 
 
Thread Tools Display Modes
  #1  
Old December 18th, 2007, 08:51 PM posted to microsoft.public.word.tables
Ron
external usenet poster
 
Posts: 690
Default Counting non-blank cells in a column

Does anyone have a formula for counting the number of cells in a column that
contain text?

We are trying to count the number of names that appear in a column.
  #2  
Old December 18th, 2007, 11:41 PM posted to microsoft.public.word.tables
Lene Fredborg
external usenet poster
 
Posts: 1,294
Default Counting non-blank cells in a column

You can use a macro. The following macro will count all non-blank cells in
the (first) column in the selection. A message displays the result.

You do not need to select the entire column before running the macro. It
will check all cells even if you have only an insertion point or if part of
the column selected.

Note that the macro will consider a cell as non-blank even if the cell
contains spaces only. Additional code can be added to prevent this if desired.

Sub CountNonBlankCellsInColumn()

Dim oCell As Cell
Dim n As Long 'used as counter

n = 0
'Check whether selection is in table
If Selection.Information(wdWithInTable) = False Then
MsgBox "The selection must be in a table. Please retry.", vbOKOnly
Exit Sub
End If
‘Check all cells in the first column in the selection
For Each oCell In Selection.Columns(1).Cells
'Check whether row is empty - delete if it is
If Len(oCell.Range.Text) 2 Then
'Cell is not empty - count
n = n + 1
End If
Next oCell

'Show message
MsgBox "The (first) column in the selection contains " & n & _
" non-blank cells."
End Sub

For help on installing macros, see:
http://www.gmayor.com/installing_macro.htm

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"Ron" wrote:

Does anyone have a formula for counting the number of cells in a column that
contain text?

We are trying to count the number of names that appear in a column.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:01 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.