VBA Macro to Hide Rows Upon Entering New Data in Named Table Range

powerpivotlegal

New Member
Joined
May 14, 2014
Messages
30
Hello,

I am extremely limited in my knowledge of VBA macros and cannot seem to find the exact solution on searching through forum posts.

I am trying to write a macro that hides the row when you mark the cell in the last column of the named table range. For example, Table Name = "Ben" for Columns A2 through J20. If J4 is marked with an "X" then hide row 4. Hide row 5 if J5 is marked with an "x", etc.

This macro will need to be continuously running so that it incorporates any new rows of data added to the named table range.

The best I could cobble together is the macro below, but it runs super slow because I had to define the range so large in order to account for possible new row additions. How can a macro just look to the range of data in just one column of the named table range?

Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Range, c As Range
Set r = Range("j2:j20000")
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
For Each c In r
If c = "X" Or c = "x" Then
c.EntireRow.Hidden = True
Else
c.EntireRow.Hidden = False
End If
Next c
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Application.ScreenUpdating = True

End Sub

Many thanks in advance.

Regards,
James
 

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
So any time a "x" or "X" is placed in column "J" you want that row hidden.
Is that what you want?
 
Upvote 0
If the answers to my previous questions are true use this script:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("J:J")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
If Target.Value = "x" Or Target.Value = "X" Then
Rows(Target.Row).Hidden = True
End If
End If
End Sub
 
Upvote 0
WOW! It works perfectly.

Knowing how picky the end-user is, is there an alternative macro that creates a button outside the named table range for the end-user to select and hide all entries of the named table range. Meaning they don't have to fill out Column J but instead click a button to hide the last or all completed rows of the table?
 
Upvote 0
And how do we know when this occurs?
Your quote:

"but instead click a button to hide the last or all completed rows of the table?"
Do you mean when every single range in the table is filled with some value.
 
Upvote 0
The end-user doesn't want to see all the rows of data after he/she adds a new row of data. I'm assuming the end-user will have filled out all the columns before they would click a button or a check box to hide the rows of data. Similar to marking the "x" in the last column to hide the row, they would instead just click a button to hide or unhide the completed row(s).
 
Upvote 0

Forum statistics

Threads
1,215,452
Messages
6,124,914
Members
449,195
Latest member
Stevenciu

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