I'm a novice at formulas, and I tried to search for the answer to this, but I'm only finding how to get complete word/character counts.
I need a formula that will look at a cell and let me specify a character, hyphen ( - ) in my case, and tell me how many times that character appeared in that cell.
So if my A1 cell is [DST-U, ARC-U], I need the formula to return "2". Could any one help me with this?
[Solved] Counting occurrence of specific character in cell
-
hypersapien
- Posts: 21
- Joined: Sun May 29, 2011 7:24 pm
[Solved] Counting occurrence of specific character in cell
Last edited by hypersapien on Sun May 29, 2011 10:30 pm, edited 1 time in total.
OpenOffice.org 3.3.0 with MacOS 10.6.7
Re: Counting occurrence of specific character in cell
B1 =ISNUMBER(FIND("-";A1)) finds the first occurrence
C1 =ISNUMBER(FIND("-";$A1;B1+1)) finds the next occurrence
copy C1 to the right and get the sum of B1:X1
C1 =ISNUMBER(FIND("-";$A1;B1+1)) finds the next occurrence
copy C1 to the right and get the sum of B1:X1
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
- MrProgrammer
- Moderator
- Posts: 5448
- Joined: Fri Jun 04, 2010 7:57 pm
- Location: Wisconsin, USA
Re: Counting occurrence of specific character in cell
Hi, and welcome to the forum.
=LEN(cell)-LEN(SUBSTITUTE(cell;"-";""))
If this answered your question please go to your first post use the Edit button and add [Solved] to the start of the title. You can select the green checkmark icon at the same time.
=LEN(cell)-LEN(SUBSTITUTE(cell;"-";""))
If this answered your question please go to your first post use the Edit button and add [Solved] to the start of the title. You can select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.8, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).
AOO 4.1.7 Build 9800, MacOS 13.7.8, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).
-
hypersapien
- Posts: 21
- Joined: Sun May 29, 2011 7:24 pm
Re: [Solved] Counting occurrence of specific character in ce
Thanks to both of you. I couldn't get Villeroy's method to work (i just got an endless row of 'TRUE' cells), but Mr's did work for me.
Mr, if I can question you further I'd like to ask how that formula works to help me learn. If I'm understanding it correctly, it is asking for the total number of characters in that cell, and then it subtracts the amount of characters in the cell minus the number of hyphens. Is this correct?
If so, then does the SUBSTITUTE portion work by replacing they hyphen ("-") with nothing ("") ?
Mr, if I can question you further I'd like to ask how that formula works to help me learn. If I'm understanding it correctly, it is asking for the total number of characters in that cell, and then it subtracts the amount of characters in the cell minus the number of hyphens. Is this correct?
If so, then does the SUBSTITUTE portion work by replacing they hyphen ("-") with nothing ("") ?
OpenOffice.org 3.3.0 with MacOS 10.6.7
- MrProgrammer
- Moderator
- Posts: 5448
- Joined: Fri Jun 04, 2010 7:57 pm
- Location: Wisconsin, USA
Re: [Solved] Counting occurrence of specific character in ce
SUBSTITUTE replaces each hyphen ("-") with nothing (""), that is, it deletes them. The difference between the LEN functions is the number of characters deleted, which is the count of the hyphens.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.8, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).
AOO 4.1.7 Build 9800, MacOS 13.7.8, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).