Count number of number and string in range

Alpacino

Well-known Member
Joined
Mar 16, 2011
Messages
511
Hi all,

I have in range a5:a267 a list of number and names

Eg 1234 Chris
6734 Luke
8790 simon
0
0
Etc

I like to count the number of cell with the numbers and text in them.

So the example above would result in 3.

Thanks in advance
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi,

Try the below code,
Code:
Dim iCount As Integer
 
Sub LoadString()
 
iCount = 0
 
For Row = 1 To 267
    CheckString = Cells(Row, 1).Value
    HasNumOrChr (CheckString)
Next Row
 
'Value of iCount will be the required output
MsgBox iCount
 
End Sub
Code:
Function HasNumOrChr(s As String) As Boolean
    Dim i As Integer
 
    For i = 1 To Len(s)
        If (Mid(s, i, 1) Like "[A-Z]" Or Mid(s, i, 1) Like "[a-z]") Then
 
        For j = 1 To Len(s)
 
            If Mid(s, j, 1) Like "[0-9]" Then
 
                HasOddChr = True
 
            End If
        Next j
 
       End If
 
    Next i
 
    If HasOddChr Then iCount = iCount + 1
 
End Function

Value of iCount will be the required output.
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,749
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top