Auto Hide / Unhide blank rows

henrym

New Member
Joined
Dec 5, 2016
Messages
5
Hello everyone,

I am new to excel VBA and hoping someone can help with a problem i have run into. My worksheet called "Data" has a cell that changes (A5) projects and based on that change I used index functions to pull multiple rows of data from another sheet. I have set up basically a range of rows (A5:U20) that these will fit in, but the problem is some projects have more rows than others, and I would like to automatically hide/unhide rows based on if they are blank or not. If more info is needed, let me know. Thanks
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
try this

Code:
Sub do_it()

Rows("5:20").Hidden = False
For Each cell In Range("A5:A20").Cells
If cell = "" Then Rows(cell.Row).Hidden = True
Next

End Sub

Ross
 
Upvote 0
Thanks for the reply,

When I put that code in, it just hides all the rows (5:20) regardless of what is in them.
 
Upvote 0
If this helps at all, here is a picture of my spreadsheet. Basically, its a drop down menu where it says "Select Project" and I will be changing that and comparing different projects. There will be data from columns E-T depending on the project, and basically no data in columns A and E. I had also changed your code accordingly since I moved some stuff around since i first posted it.

Here's a link if the picture didn't load
view.php

(Image - TinyPic - Free Image Hosting, Photo Sharing & Video Hosting)
 
Upvote 0
Awesome, I got it working. Now, at this point I assigned it to a button, but is there any way that it could just be automatic? And again, thanks for your time, this is super useful for me.
 
Upvote 0
> Now, at this point I assigned it to a button,

Have you thought about using Autofilter on the column?
 
Upvote 0
to get it to auto run when you change cell A5
Right click on sheet name - view code - then paste this in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A5")) Is Nothing Then Do_it
End Sub
 
Last edited:
Upvote 0
@Err, yeah. The workbook had previously used an autofilter, and it was just clunky and didn't work too well with the data

@rpaulson you're a genius. thank you so much for the help, it all works perfectly.
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,298
Members
449,077
Latest member
Rkmenon

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