Need Help - New to VBA, looking to hide rows, based on cell contents

jmetime

New Member
Joined
Jun 7, 2019
Messages
1
Hi All,

I need some assistance. I'm VERY new at this.
I've created a report, where I use data from Sheet 1 to populate some of the cells in Sheet 2, column B being one of them
I'm not sure how I want to go about this. But I want the row to be hidden if the B cell is empty on Sheet 2.

So if Sheet2 B9 is empty, I want that row to be hidden but Sheet 2 B9 contains whatever is in Sheet 1 B9 (so it's not necessarily blank)..
I need to do this for the whole report, each row being visible is dependent on if anything is in the B column
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I'm not sure how this can be possible.
Your saying if any cell in sheet2 column B is empty you want that row hidden.
But the cell is not empty but you still want that cells row hidden.

And on sheet2 column B there are about 1.5 million cells. So do you want all 1.5 million rows hidden?
 
Upvote 0
You could possibly filter rather than hide
Code:
Sub FilterOutBlank_B_Rows()
    Dim ws As Worksheet
    Dim lr As Long
Set ws = Sheets("Sheet2")
With ws
    'find very last used cell
    lr = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    'filter for column with the blanks
    .Range("B1:B" & lr).AutoFilter field:=1, Criteria1:="<>", Operator:=xlFilterValues, VisibleDropDown:=False
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,038
Messages
6,128,447
Members
449,453
Latest member
jayeshw

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