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?
3
<= Maximum rows to show

Artist
Song Title
Album
Rating
Artist 1 Song 1Album A5 Stars
Artist 1 Song 2Album A5 Stars
Artist 1 Song 5Album B4 Stars
Artist 2Song 1Album A5 Stars
Artist 2Song 2Album C5 Stars
Artist 2Song 3Album A5 Stars
Artist 3Song 1Album C5 Stars
Artist 3Song 4Album A4 Stars
Artist 3Song 5Album C3 Stars
Artist 4Song 1Album A5 Stars
Artist 4Song 2Album B4 Stars
Artist 4Song 3Album A3 Stars
etcetc etc etc

<tbody>
</tbody>

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.:oops:
Any help would be appreciated.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
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. :oops:

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

Forum statistics

Threads
1,216,030
Messages
6,128,408
Members
449,448
Latest member
Andrew Slatter

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