Display Specified Number of Rows per Values in Column A

MarqyMarq

New Member
Joined
Oct 22, 2015
Messages
30
Office Version
  1. 2016
Platform
  1. Windows
I am using Excel 2010. My son has a spreadsheet that has several hundreds of rows of titles of artist, songs, song length, rating, and so forth. I want to limit the number of rows to display for each artist, based on their rating. Let’s say, either 5 rows per artist, 10 rows per artist, or show all. The options (5, 7, all) to list would be in a CELL value at the top of my listing.

I think I can use an array, with Index and CountA, but I don’t know how to set it up. Any recommendations on how to start this?
[TABLE="width: 517"]
<tbody>[TR]
[TD="align: center"]3
[/TD]
[TD]<= Maximum rows to show

[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Artist
[/TD]
[TD]Song Title
[/TD]
[TD]Album
[/TD]
[TD]Rating [/TD]
[/TR]
[TR]
[TD]Artist 1 [/TD]
[TD]Song 1[/TD]
[TD]Album A[/TD]
[TD]5 Stars[/TD]
[/TR]
[TR]
[TD]Artist 1 [/TD]
[TD]Song 2[/TD]
[TD]Album A[/TD]
[TD]5 Stars[/TD]
[/TR]
[TR]
[TD]Artist 1 [/TD]
[TD]Song 5[/TD]
[TD]Album B[/TD]
[TD]4 Stars [/TD]
[/TR]
[TR]
[TD]Artist 2[/TD]
[TD]Song 1[/TD]
[TD]Album A[/TD]
[TD]5 Stars[/TD]
[/TR]
[TR]
[TD]Artist 2[/TD]
[TD]Song 2[/TD]
[TD]Album C[/TD]
[TD]5 Stars[/TD]
[/TR]
[TR]
[TD]Artist 2[/TD]
[TD]Song 3[/TD]
[TD]Album A[/TD]
[TD]5 Stars[/TD]
[/TR]
[TR]
[TD]Artist 3[/TD]
[TD]Song 1[/TD]
[TD]Album C[/TD]
[TD]5 Stars[/TD]
[/TR]
[TR]
[TD]Artist 3[/TD]
[TD]Song 4[/TD]
[TD]Album A[/TD]
[TD]4 Stars [/TD]
[/TR]
[TR]
[TD]Artist 3[/TD]
[TD]Song 5[/TD]
[TD]Album C[/TD]
[TD]3 Stars[/TD]
[/TR]
[TR]
[TD]Artist 4[/TD]
[TD]Song 1[/TD]
[TD]Album A[/TD]
[TD]5 Stars[/TD]
[/TR]
[TR]
[TD]Artist 4[/TD]
[TD]Song 2[/TD]
[TD]Album B[/TD]
[TD]4 Stars [/TD]
[/TR]
[TR]
[TD]Artist 4[/TD]
[TD]Song 3[/TD]
[TD]Album A[/TD]
[TD]3 Stars[/TD]
[/TR]
[TR]
[TD]etc[/TD]
[TD]etc [/TD]
[TD]etc [/TD]
[TD]etc [/TD]
[/TR]
</tbody>[/TABLE]

I’ve tried searching on the internet and tested code and have failed for hours. I have come to a complete stop and I just can’t find the solution to this problem.:banghead:
Any help would be appreciated.
 
Sub myHide()
sht = "Sheet1"
rowsHideCell = "A1"
showNumberOfRows = Sheets(sht).Range(rowsHideCell).Value
firstRow = 3
lastRow = Sheets(sht).Range("A" & Rows.Count).End(xlUp).Row
Sheets(sht).Rows(firstRow & ":1048576").Hidden = False
r = firstRow
Do Until r > lastRow
rArtistName = Sheets(sht).Range("A" & r).Value
ArtistCounter = 0
rSearch = r
Do Until rSearch > lastRow
rSearchArtistName = Sheets(sht).Range("A" & rSearch).Value
If rArtistName = rSearchArtistName Then
If ArtistCounter > showNumberOfRows Then
Rows(rSearch).Hidden = True
End If
ArtistCounter = ArtistCounter + 1
End If
rSearch = rSearch + 1
Loop
r = r + 1
Loop
End Sub
 
Last edited:
Upvote 0
Solution
Thanks WarPigl3t for the response. Unfortunately, when I plugged the code into my spreadsheet, nothing happened. Could it be that the variables were not declared?

Let me recap what I wish the code to do:

1) The options of "3", "5", "7", or "None" would be selected (data validation list) by my son. This value is placed in cell "A1".
2) Sort by Artist, and then by Rating. The info on rows 1 & 2 would NOT be hidden.
3) Starting on row 3, hide the excess rows (over 3, 5, or 7) based on Artist. NOTE: If "None" is selected, it would skip this process (If-then-else).
4) The result would be an Artist List with the top x# displayed in the spreadsheet. The spreadsheet name is "Summary".

So, I reviewed the code and added some variable declarations (sht) and (r). It still didn't work. :banghead:

WarPigl3t, if you can review the code and see where I may have messed up, that would be great!

Thanks in advance!!!
 
Last edited:
Upvote 0

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