Count number of names in a cell

mrkris1982

Active Member
Joined
Apr 16, 2009
Messages
407
I2 has 3 names in it...cell looks like this....

Bob Jones
Doug Smith
Chase Williams

I'd like to get J2 to show the number 3 - reflecting the number of names in I2. Is there a way to do this?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
It's only returning odd values (1,3,5,7, etc...)

I did adjust the "A1" to be "I1" but the rest is exactly as suggested


The issue in my case might be that I have a dropdown list in column I with some VBA code that allows me to select a person....and they are added to the cell.....select another person and they are added to the cell on a new line.

When I try your formula on a cell where I manually enter a name, make a new line and enter a new name....the formula works. Think there is a way to make it work for the dropdown list where im selecting multiple names?
 
Last edited:
Upvote 0
Can you post the code you are using
 
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Range)'Code by Sumit Bansal from https://trumpexcel.com
' To allow multiple selections in a Drop Down List in Excel (without repetition)
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
If Target.Address = "$I$2" Then
  If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
    GoTo Exitsub
  Else: If Target.Value = "" Then GoTo Exitsub Else
    Application.EnableEvents = False
    Newvalue = Target.Value
    Application.Undo
    Oldvalue = Target.Value
      If Oldvalue = "" Then
        Target.Value = Newvalue
      Else
        If InStr(1, Oldvalue, Newvalue) = 0 Then
            Target.Value = Oldvalue & vbNewLine & Newvalue
      Else:
        Target.Value = Oldvalue
      End If
    End If
  End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub
 
Upvote 0
In that case try
=IF(A1="","",LEN(A1)-LEN(SUBSTITUTE(A1,CHAR(10),""))+1)
 
Upvote 0
This is what I get

Excel 2013/2016
IJ
5Fluff mrkris1982 MrExcel3
6Fluff1
7Fluff Me2
Color
Cell Formulas
RangeFormula
J5=IF(I5="","",LEN(I5)-LEN(SUBSTITUTE(I5,CHAR(10),""))+1)
 
Upvote 0
brain fart on my end - this works. I failed to adjust the row along with the column. I needed I2 and was using I1

Thanks!
 
Upvote 0

Forum statistics

Threads
1,214,375
Messages
6,119,167
Members
448,870
Latest member
max_pedreira

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