VBA Help - Hide/Unhide Rows if Column is blank Loop

AF1988

New Member
Joined
Feb 22, 2019
Messages
7
Hello,

I was hoping someone could help out please? I've searched through plenty of threads to find an answer but can't seem to find it.

I have a spreadsheet containing Array VLOOKUPS that display either a 0 or data in the cell range B24:I223 when an account code is entered in to Cell K2.

I have the code displayed below that hides any rows where 0 is in the cell range B24:B223, and so only displays the rows that have data in them.

What I really need is for this to effectively rerun when Cell K2 is updated with a different account code, and then un-hide any rows with a non-0 value, and hide any that does contain 0.

To top it off, this needs to be a quick run too as I tried using a Worksheet_Change (ByVal Target as Range) but this was way way too slow.

Option Explicit
Private Sub Worksheet_Activate()
Dim r As Range, c As Range
Set r = Range("B24:B223")
Application.ScreenUpdating = False
For Each c In r.Rows
If Len(c.Cells(1).Text) + Len(c.Cells(2).Text) = 0 Then
c.EntireRow.Hidden = True
Else
c.EntireRow.Hidden = False
End If
Next c
Application.ScreenUpdating = True
End Sub

Thank you in advance to anyone that can help!

Kind regards,
AF1988
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Is Row 24 the header row, or the first set of data?
 
Upvote 0
In that case try
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Application.ScreenUpdating = True
   Application.Calculation = xlCalculationManual
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Address(0, 0) = "K2" Then
      Range("B23:L223").AutoFilter 1, "<>"
   End If
   Application.Calculation = xlCalculationAutomatic
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,039
Messages
6,122,799
Members
449,095
Latest member
m_smith_solihull

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