Counting Groups Of Cells

FALLSILENT

New Member
Joined
Oct 5, 2017
Messages
9
Hi,
I'm using a spreadsheet for utilization. I use different letters for different meanings. One of them is "R" I'm trying to find a way that it will count how many "R's are in a row, but only count groups.


[TABLE="width: 1067"]
<colgroup><col width="48" span="4"><col width="59"><col width="48" span="17"></colgroup><tbody>[TR]
[TD="class: xl65, width: 48"]R[/TD]
[TD="class: xl64, width: 48"]R[/TD]
[TD="class: xl64, width: 48"]R[/TD]
[TD="class: xl64, width: 48"]L[/TD]
[TD="class: xl64, width: 59"]L[/TD]
[TD="class: xl64, width: 48"]L[/TD]
[TD="class: xl64, width: 48"]L[/TD]
[TD="class: xl64, width: 48"]R[/TD]
[TD="class: xl64, width: 48"]R[/TD]
[TD="class: xl64, width: 48"]R[/TD]
[TD="class: xl65, width: 48"]R[/TD]
[TD="class: xl65, width: 48"]R[/TD]
[TD="class: xl65, width: 48"]R[/TD]
[TD="class: xl65, width: 48"]R[/TD]
[TD="class: xl65, width: 48"]R[/TD]
[TD="class: xl65, width: 48"]R[/TD]
[TD="class: xl65, width: 48"]L[/TD]
[TD="class: xl65, width: 48"]L[/TD]
[TD="class: xl65, width: 48"]L
[/TD]
[TD="class: xl65, width: 48"]R
[/TD]
[TD="class: xl65, width: 48"]L[/TD]
[TD="class: xl65, width: 48"]L[/TD]
[/TR]
</tbody>[/TABLE]


And At The End Count "R" as 3. I Know How To Count All Of Them, But I Want To Only Count The Groups.

Thanks In Advance!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hope this helps.

Code:
Sub test()
Dim rng As Range, c
Dim cnt As Long, cnt1 As Long, buf As String
buf = "L"
Set rng = Range(Range("A2"), cells(2, Columns.count).End(xlToLeft))
For Each c In rng
   buf = buf & c.Value
Next
cnt = Len(buf)
cnt1 = Len(WorksheetFunction.Substitute(buf, "LR", "$"))
MsgBox cnt - cnt1
End Sub
 
Upvote 0
Hi,

If you want a formula solution and don't mind a helper row:


Book1
ABCDEFGHIJKLMNOPQRSTUVW
1RRRLLLLRRRRRRRRRLLLRLLCount of R Series
2 RLRLRL3
Sheet53
Cell Formulas
RangeFormula
A2=IF(A1=B1,"",A1)
W2=COUNTIF(A2:V2,"R")


A2 formula copied across to V2.
 
Last edited:
Upvote 0
Just a question. Trying to learn. Why substitute "LR" with "$". Trying to find out what "$" means?

Code:
Len(WorksheetFunction.Substitute(buf, "LR", "$"))
 
Upvote 0
Just a question. Trying to learn. Why substitute "LR" with "$". Trying to find out what "$" means?

Code:
Len(WorksheetFunction.Substitute(buf, "LR", "$"))


Yes! I've wondered that, but haven't had the time to sit down and read up that far yet.
 
Upvote 0
There is no special reason.
It just change the "LR" to "$" then counts the difference in number of letters.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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