Hiding Rows based on Cell Value

Davis10

New Member
Joined
Jun 21, 2011
Messages
27
I have a worksheet I use for conferences to estimate travel costs for attendees. On the first worksheet I have a list of all attendees and based on what type of employee they are, it populates different worksheets in the workbook. There is a possible 400 attendees but i need the worksheets to hide the rows if there are not that many, ie if there is 10 type A employees rows 11-400 are hidden. Currently I have

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$5" Then
Rows("7:400").Hidden = (Target.Value = "0")
Rows("8:400").Hidden = (Target.Value = "1")
etc.
End If
End Sub

Is there a way to loop this so I do not have to input 400 lines of code?
Also, is there a way to check the target cell every time the page is open so if like before there was 10 type A people and someone was added to the original worksheet that this page, when clicked on, would unhide the correct rows?

Thanks
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
There is a possible 400 attendees but i need the worksheets to hide the rows if there are not that many, ie if there is 10 type A employees rows 11-400 are hidden.
Why not just have it find the last row with data in it, and hide the rest (rather than check each one individually)?
 
Upvote 0
Which column can we use to determine where the last row of data is (i.e. a column that always has to be populated for each row of data)?
 
Upvote 0
Code:
    Dim myLastRow
    myLastRow = Cells(Rows.Count, "A").End(xlUp).Row
    Rows(myLastRow & ":400").Hidden = True
 
Upvote 0
Hmm I cannot get it to work properly...any ideas as to what I should put as the Private Sub?

Or any other reasons it may not work?
 
Upvote 0
I can try to recreate your situation, but I'll need the following to do so:
- explain what the data looks like at first (post a small sampling, maybe)
- explain what you are doing that should call your code
- explain what your expected result is
- explain what is actually happening
 
Upvote 0
In columns A, B, C, D is the Name, Address, State and Zip Code, respectively. On a previous worksheet, in the workbook, there is a master list of names and an employee code which designates which worksheet they will populate to. My expected result is to populate the rows on the specific employee worksheets and hide the rows which are not shown. If there is a possible number of 400 attendees but if only 50 populate a certain worksheet then the rows 51-400 need to be hidden. It also needs to be able to update if names were added to the original list. An example would be like the 50 people from before and having rows 51-400 hidden but then someone was added to the original worksheet which falls in the same category so now the worksheet needs to have row 51 visible and hide rows 52-400. Currently I cannot get anything to happen.
 
Upvote 0
So, do you have some sort of process that is actually doing the copying of the data from the master tabs into your other tabs?
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p> </o:p>
And are you saying that you want to hide these unused rows on all of the individual employee worksheets?
<o:p> </o:p>
If so, I don’t think that you want to use the Worksheet_Change event procedure, as that one runs when something on that particular sheet is changed (so you would need that code on each sheet). Rather, I think it would work better. To have some VBA code that runs on the back-end of your data move process that loops through all the sheets and hides the appropriate rows, using the code I provided.
<o:p> </o:p>
Does it sound like that would work in your situation?
 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,423
Members
448,961
Latest member
nzskater

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