Count Cells

helpexcel

Well-known Member
Joined
Oct 21, 2009
Messages
656
Hi - If i have Data in column A, that also has multiple headings, is there a way for me to say in A:A count cells between "Beach" and "Baseball"?
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
One way would be
Code:
Sub Maybe()
    MsgBox Range(Columns(1).Find("Beach").Offset(1), Columns(1).Find("Baseball").Offset(-1)).Cells.Count
End Sub
 
Upvote 0
What is the expected result for the scenario below?


[Table="class: grid"][tr][td="bgcolor: #DCE6F1"][/td][td="bgcolor: #DCE6F1"]
A
[/td][/tr]
[tr][td="bgcolor: #DCE6F1"]
1
[/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
2
[/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
3
[/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
4
[/td][td]
Baseball​
[/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
5
[/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
6
[/td][td]
Beach​
[/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
7
[/td][td][/td][/tr]
[/table]


M.
 
Upvote 0
Code:
=MATCH("Baseball", A2:A29, 0)-MATCH("Beach", A2:A29, 0)-1

If you don't know which value is going to be the first one, you might have to resort t something like this.
Code:
Sub Maybe_C()
Dim i As Long, ii As Long
i = ActiveSheet.Columns(1).Find("Beach").Row
ii = ActiveSheet.Columns(1).Find("Baseball").Row
    MsgBox IIf(ii > i, ii - (i + 1), i - (ii + 1))
End Sub

@Marcelo
We'll wait for an answer I guess but the way I read the first Post, it should be 1 (one)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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