Count Cells containing Text only

N

Nick Hodge

Soniya

the code below will count the cells with constants. (Not formulas, blank,
etc) in a selection

Sub CountConstants()
Dim lConstantCount As Long
lConstantCount = Selection.SpecialCells(xlCellTypeConstants).Count
MsgBox "There are " & lConstantCount & " Cells with constants in the
selection"
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
(e-mail address removed)
 
J

JMay

Perhaps you are looking for a programming answer and not a function answer,
anyway this single **Array-entered** formula is better. Use Ctrl+Shift+Enter
after
keying or pasting in:

=SUM(ISTEXT(A1:A100)*ISTEXT(A1:A100))

HTH
 
T

Tom Ogilvy

Nick, think you meant to include the second argument as well:

Sub CountConstants()
Dim lConstantCount As Long
On Error Resume Next
lConstantCount = Selection.SpecialCells( _
xlCellTypeConstants,xlTextValues).Count
On Error goto 0
MsgBox "There are " & lConstantCount _
& " Cells with constants in the
selection"
End Sub

Just in case there are constant numbers in the selection as well.
 

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