Date: 3/11/2014 14:20:29
From: JTQ
ID: 621491
Subject: Excel Help

Hi all

Hopefully someone knows how to do this… I’ve got 156 rows of data in Excel and need to count the number of occurrences of a string within each cell in a specific column.

”““let DorQ3:=0; let Dor3:=”“”“; let DorT3:=1; let DorB3:=0; let DorQ2:=0; let Dor2:=”“”“; let DorT2:=1; let DorB2:=0; let DorQ:=0; let Dor:=”“”“; let DorT:=1; let DorB:=0; let CSub:=1; let Pan:=1; let V:=( “”|P|C”“ ); let Drw1:=1; let CarU:= Array(, , , , , , , , , ); let CarE:=No; let CarS:=Yes; let X1:=”“”“; let X2:=”“”“; let X3:=”“”“; let A:=MatXXType; let DorB:=0; let Pan1:=(if MatXPanelDoor then 2 else 1); let Car:=1; let Car1:=(if MatXCarcPanel then 2 else 1); let CarL:=(if MatXEndPanelL then 2 else 1); let CarR:=(if MatXEndPanelR then 2 else 1); let Ben:=0; let Kic:=0; let Fin:=1; let Fin1:=(if MatXFingerPanel then 2 else 1); ShowFriendlyPages(AALangFind(““Word”“,”“$Material”“), AALangFind(““QIQ”“, ““FP-MatCabinet.qiq”“), , ); setvalue(““MatXOptDor”“,1)”“”

I need to know how many occurrences there are of “Dor” in this, as well as the other 155 rows. Any ideas how this might be achieved?

Any help greatly appreciated, and worthy of free beers all night at the next pud I’m at :)

Reply Quote

Date: 3/11/2014 14:24:12
From: diddly-squat
ID: 621494
Subject: re: Excel Help

=COUNTIF(range,"string")

Reply Quote

Date: 3/11/2014 14:26:06
From: JTQ
ID: 621495
Subject: re: Excel Help

diddly-squat said:


=COUNTIF(range,"string")

With the data shown in my OP in yellow, the result from that formula is zero.

Reply Quote

Date: 3/11/2014 14:29:48
From: diddly-squat
ID: 621500
Subject: re: Excel Help

JTQ said:


diddly-squat said:

=COUNTIF(range,"string")

With the data shown in my OP in yellow, the result from that formula is zero.

then you have cocked up the formula

=COUNTIF(A1:A156,"Dor")

that should return the number of instances of the string “Dor” in the range A1:A156.

Reply Quote

Date: 3/11/2014 14:31:59
From: furious
ID: 621503
Subject: re: Excel Help

Did you replace “string” with the text you are looking for? Also:

Crt-H
Find What: Dor
Replace with: Dor
Replace All

will tell you how many there are…

Reply Quote

Date: 3/11/2014 14:34:29
From: Tamb
ID: 621506
Subject: re: Excel Help

furious said:

  • With the data shown in my OP in yellow, the result from that formula is zero.

Did you replace “string” with the text you are looking for? Also:

Crt-H
Find What: Dor
Replace with: Dor
Replace All

will tell you how many there are…


That was my first thought but while it replaced properly it didn’t tell me how many were replaced.

Reply Quote

Date: 3/11/2014 14:35:10
From: The Rev Dodgson
ID: 621507
Subject: re: Excel Help

Suppose your list of strings starts in A2, then:

In B2 enter: =FIND
In C2 enter: =FIND
Copy C2 across to cover more than the maximum number of “Dor“s. Each cell will contain an offset number to the position of the next Dor, until it can’t find any more, then it will display #VALUE.
In the next column (say R) enter =COUNTIF
Adjust the Q to whatever your last column is.
Copy Columns B to R (or whatever) down for the complete list.

I think you’d need some VBA to do it in a single cell.

Reply Quote

Date: 3/11/2014 14:36:12
From: furious
ID: 621510
Subject: re: Excel Help

For the text in the first post my excel says:

Excel has completed its search and has made 14 replacements.

Reply Quote

Date: 3/11/2014 14:36:38
From: The Rev Dodgson
ID: 621512
Subject: re: Excel Help

diddly-squat said:


JTQ said:

diddly-squat said:

=COUNTIF(range,"string")

With the data shown in my OP in yellow, the result from that formula is zero.

then you have cocked up the formula

=COUNTIF(A1:A156,"Dor")

that should return the number of instances of the string “Dor” in the range A1:A156.

That formula will count the number of cells that contain “Dor” and nothing else.

Reply Quote

Date: 3/11/2014 14:38:54
From: Tamb
ID: 621517
Subject: re: Excel Help

furious said:

  • That was my first thought but while it replaced properly it didn’t tell me how many were replaced.

For the text in the first post my excel says:

Excel has completed its search and has made 14 replacements.


I have a very ancient version of Excel. Don’t think it knows how to count.

Reply Quote

Date: 3/11/2014 14:40:52
From: diddly-squat
ID: 621518
Subject: re: Excel Help

The Rev Dodgson said:


diddly-squat said:

JTQ said:

With the data shown in my OP in yellow, the result from that formula is zero.

then you have cocked up the formula

=COUNTIF(A1:A156,"Dor")

that should return the number of instances of the string “Dor” in the range A1:A156.

That formula will count the number of cells that contain “Dor” and nothing else.

ummm… yes… is that not what he wants??

Reply Quote

Date: 3/11/2014 14:42:07
From: The Rev Dodgson
ID: 621520
Subject: re: Excel Help

The Rev Dodgson said:


Suppose your list of strings starts in A2, then:

In B2 enter: =FIND
In C2 enter: =FIND
Copy C2 across to cover more than the maximum number of “Dor“s. Each cell will contain an offset number to the position of the next Dor, until it can’t find any more, then it will display #VALUE.
In the next column (say R) enter =COUNTIF
Adjust the Q to whatever your last column is.
Copy Columns B to R (or whatever) down for the complete list.

I think you’d need some VBA to do it in a single cell.

Formulas are:
=FIND string in quotes,$A2
=FIND string in quotes,$A2, B2+1
=COUNTIF B2:Q2,>0 in quotes

With brackets where appropriate!

Reply Quote

Date: 3/11/2014 14:43:22
From: The Rev Dodgson
ID: 621522
Subject: re: Excel Help

diddly-squat said:


The Rev Dodgson said:

diddly-squat said:

then you have cocked up the formula

=COUNTIF(A1:A156,"Dor")

that should return the number of instances of the string “Dor” in the range A1:A156.

That formula will count the number of cells that contain “Dor” and nothing else.

ummm… yes… is that not what he wants??

No, he wants the number of “Dors“s in a long string in each cell.

Reply Quote

Date: 3/11/2014 14:44:42
From: The Rev Dodgson
ID: 621523
Subject: re: Excel Help

The Rev Dodgson said:

Formulas are:
=FIND string in quotes,$A2
=FIND string in quotes,$A2, B2+1
=COUNTIF B2:Q2,>0 in quotes

With brackets where appropriate!

Or click on quote, and see the originals!

Reply Quote

Date: 3/11/2014 14:44:47
From: Tamb
ID: 621524
Subject: re: Excel Help

diddly-squat said:


The Rev Dodgson said:

diddly-squat said:

then you have cocked up the formula

=COUNTIF(A1:A156,"Dor")

that should return the number of instances of the string “Dor” in the range A1:A156.

That formula will count the number of cells that contain “Dor” and nothing else.

ummm… yes… is that not what he wants??


Provided that it only counts Dor & not Dorsal or adorable etc.

Reply Quote

Date: 3/11/2014 14:48:32
From: diddly-squat
ID: 621525
Subject: re: Excel Help

The Rev Dodgson said:


diddly-squat said:

The Rev Dodgson said:

That formula will count the number of cells that contain “Dor” and nothing else.

ummm… yes… is that not what he wants??

No, he wants the number of “Dors“s in a long string in each cell.

I see…

Reply Quote

Date: 3/11/2014 14:52:10
From: The Rev Dodgson
ID: 621526
Subject: re: Excel Help

ds – just seen how you got the formulas to display properly.

I’ll try and remember the at trick.

Reply Quote

Date: 3/11/2014 14:55:23
From: The Rev Dodgson
ID: 621527
Subject: re: Excel Help

Formulas with ats:

Suppose your list of strings starts in A2, then:

In B2 enter: =FIND("Dor",$A2)
In C2 enter: =FIND("Dor",$A2,B2+1)
Copy C2 across to cover more than the maximum number of “Dor“s. Each cell will contain an offset number to the position of the next Dor, until it can’t find any more, then it will display #VALUE.
In the next column (say R) enter =COUNTIF(B2:Q2,">0")
Adjust the Q to whatever your last column is.
Copy Columns B to R (or whatever) down for the complete list.

I think you’d need some VBA to do it in a single cell.

Reply Quote

Date: 3/11/2014 15:12:36
From: JTQ
ID: 621536
Subject: re: Excel Help

All up, there are 6095 “Dor” references in the 156 rows. This includes DorQ3, DorT3, DorB3, DorQ2, DorQ, Dor, DorT, etc…

Just need to know how many instances of “Dor” there are (including those above, DorQ3, etc) in each individual cell.

Reply Quote

Date: 3/11/2014 15:17:16
From: JTQ
ID: 621540
Subject: re: Excel Help

Another Google search and apparently this one works. Getting a different result tho.

=SUM(LEN(B1)-LEN(SUBSTITUTE(B1,"Dor","")))/LEN("Dor")

Yellow data from OP returns 38 instances of “Dor”.

Reply Quote

Date: 3/11/2014 15:20:09
From: The Rev Dodgson
ID: 621543
Subject: re: Excel Help

JTQ said:


All up, there are 6095 “Dor” references in the 156 rows. This includes DorQ3, DorT3, DorB3, DorQ2, DorQ, Dor, DorT, etc…

Just need to know how many instances of “Dor” there are (including those above, DorQ3, etc) in each individual cell.

My formulas will give you that.

Reply Quote

Date: 3/11/2014 15:23:35
From: The Rev Dodgson
ID: 621545
Subject: re: Excel Help

JTQ said:


Another Google search and apparently this one works. Getting a different result tho.

=SUM(LEN(B1)-LEN(SUBSTITUTE(B1,"Dor","")))/LEN("Dor")

Yellow data from OP returns 38 instances of “Dor”.

That’s pretty clever.

I get 14 using that with your OP data, the same as I get with my method.

Reply Quote

Date: 3/11/2014 15:50:18
From: JTQ
ID: 621570
Subject: re: Excel Help

The Rev Dodgson said:


JTQ said:

Another Google search and apparently this one works. Getting a different result tho.

=SUM(LEN(B1)-LEN(SUBSTITUTE(B1,"Dor","")))/LEN("Dor")

Yellow data from OP returns 38 instances of “Dor”.

That’s pretty clever.

I get 14 using that with your OP data, the same as I get with my method.

Not sure why you’re getting 14 when I’m constantly getting 38??

Reply Quote

Date: 3/11/2014 15:51:58
From: The Rev Dodgson
ID: 621572
Subject: re: Excel Help

JTQ said:


The Rev Dodgson said:

JTQ said:

Another Google search and apparently this one works. Getting a different result tho.

=SUM(LEN(B1)-LEN(SUBSTITUTE(B1,"Dor","")))/LEN("Dor")

Yellow data from OP returns 38 instances of “Dor”.

That’s pretty clever.

I get 14 using that with your OP data, the same as I get with my method.

Not sure why you’re getting 14 when I’m constantly getting 38??

I don’t know either.

Are you sure the string in the OP is the same as the one you are getting 38 with?

Did you try my method?

Reply Quote

Date: 3/11/2014 16:24:02
From: JTQ
ID: 621610
Subject: re: Excel Help

The Rev Dodgson said:


JTQ said:

The Rev Dodgson said:

That’s pretty clever.

I get 14 using that with your OP data, the same as I get with my method.

Not sure why you’re getting 14 when I’m constantly getting 38??

I don’t know either.

Are you sure the string in the OP is the same as the one you are getting 38 with?

Did you try my method?

Yeh I did and still got 38.

Just checked it again now and the string in OP is only half the length of what’s in the cell. Turns out going to the beginning of the cell and pressing Ctrl-Shift-End doesn’t highlight the entire cell’s contents like I thought it would.

”““let DorQ3:=0; let Dor3:=”“”“; let DorT3:=1; let DorB3:=0; let DorQ2:=0; let Dor2:=”“”“; let DorT2:=1; let DorB2:=0; let DorQ:=0; let Dor:=”“”“; let DorT:=1; let DorB:=0; let CSub:=1; let Pan:=1; let V:=( “”|P|C”“ ); let Drw1:=1; let CarU:= Array(, , , , , , , , , ); let CarE:=No; let CarS:=Yes; let X1:=”“”“; let X2:=”“”“; let X3:=”“”“; let A:=MatXXType; let DorB:=0; let Pan1:=(if MatXPanelDoor then 2 else 1); let Car:=1; let Car1:=(if MatXCarcPanel then 2 else 1); let CarL:=(if MatXEndPanelL then 2 else 1); let CarR:=(if MatXEndPanelR then 2 else 1); let Ben:=0; let Kic:=0; let Fin:=1; let Fin1:=(if MatXFingerPanel then 2 else 1); ShowFriendlyPages(AALangFind(““Word”“,”“$Material”“), AALangFind(““QIQ”“, ““FP-MatCabinet.qiq”“), , ); setvalue(““MatXOptDor”“,1)”“”

38.

Reply Quote

Date: 3/11/2014 16:24:32
From: JTQ
ID: 621611
Subject: re: Excel Help

Ahh …

Seems this forum truncates long strings?

"""let DorQ3:=0; let Dor3:=""""; let DorT3:=1; let DorB3:=0; let DorQ2:=0; let Dor2:=""""; let DorT2:=1; let DorB2:=0; let DorQ:=0; let Dor:=""""; let DorT:=1; let DorB:=0; let CSub:=1; let Pan:=1; let V:=( ""|P|C"" ); let Drw1:=1; let CarU:= Array(, , , , , , , , , ); let CarE:=No; let CarS:=Yes; let X1:=""""; let X2:=""""; let X3:=""""; let A:=MatXXType; let DorB:=0; let Pan1:=(if MatXPanelDoor then 2 else 1); let Car:=1; let Car1:=(if MatXCarcPanel then 2 else 1); let CarL:=(if MatXEndPanelL then 2 else 1); let CarR:=(if MatXEndPanelR then 2 else 1); let Ben:=0; let Kic:=0; let Fin:=1; let Fin1:=(if MatXFingerPanel then 2 else 1); ShowFriendlyPages(AALangFind(""Word"",""$Material""), AALangFind(""QIQ"", ""FP-MatCabinet.qiq""), , ); setvalue(""MatXOptDor"",1)"""

Reply Quote

Date: 3/11/2014 16:24:55
From: JTQ
ID: 621612
Subject: re: Excel Help

Yes, yes it does.

Nevermind anyway .. .turns out there’s 38

Cheers :)

Reply Quote

Date: 3/11/2014 16:27:21
From: JTQ
ID: 621616
Subject: re: Excel Help

For reference

Reply Quote

Date: 3/11/2014 16:29:32
From: The Rev Dodgson
ID: 621620
Subject: re: Excel Help

JTQ said:


Yes, yes it does.

Nevermind anyway .. .turns out there’s 38

Cheers :)

Glad its working then.

Reply Quote

Date: 4/11/2014 00:10:06
From: diddly-squat
ID: 622220
Subject: re: Excel Help

JTQ said:


Another Google search and apparently this one works. Getting a different result tho.

=SUM(LEN(B1)-LEN(SUBSTITUTE(B1,"Dor","")))/LEN("Dor")

Yellow data from OP returns 38 instances of “Dor”.

that’s rather elegant

Reply Quote

Date: 4/11/2014 01:29:37
From: SCIENCE
ID: 622223
Subject: re: Excel Help

square bracket fail

Reply Quote

Date: 4/11/2014 08:22:07
From: The Rev Dodgson
ID: 622234
Subject: re: Excel Help

cryptically worded phrase

Reply Quote

Date: 4/11/2014 08:37:03
From: MartinB
ID: 622242
Subject: re: Excel Help

Gratuitously irrelevant observation

Reply Quote