Automatically Hide Row on Another Worsheet

Chili14

New Member
Joined
Dec 21, 2016
Messages
8
Could someone help me write a script that will automatically hide rows on a "Summary" worksheet base on selections made from a "List" worksheet. The calculated values in column A ("QTY") on the "Summary" worksheet are "" when not selected from the "List" worksheet. I found some script that I modified to work looking at the calculated value "" but it only runs when selecting a cell or hitting Enter when in the "Summary" worksheet. Ideally I would like the "Summary" Worksheet to update as soon as the selection is made on the "List" worksheet so when viewing in split screen mode the "Summary" worksheet is updated automatically, without having to select a cell or hitting enter. Is this possible?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = False
Dim LastRow As Long
LastRow = Cells.Find("""", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Dim cell As Range
ActiveSheet.UsedRange.Rows.EntireRow.Hidden = False
For Each cell In Range("a4:a" & LastRow)
If cell.Value = "" Then
cell.EntireRow.Hidden = True
End If
Next cell
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
If I understood correctly, you have formulas in column A of the "Summary" sheet. These formulas calculate when you select a cell in the "List" sheet. When a selection is made in the "List" sheet, you want all rows in column A of the "Summary" that are blank to be hidden. Is this what you want to do?
 
Upvote 0
That's correct. To be clear the formulas in row A of the "Summary" sheet returns "" when True. I will add that I'm only hiding rows on the "Summary" sheet with "", and between A4 and "last Row". My actual last Row is the summation of all the columns and does not have "the formula".
 
Upvote 0
Place this macro in the code module for the "Summary" worksheet.
Code:
Private Sub Worksheet_Calculate()
    Application.ScreenUpdating = False
    Dim LastRow As Long, cel As Range
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    ActiveSheet.UsedRange.Rows.EntireRow.Hidden = False
    For Each cel In Range("A4:A" & LastRow - 1)
        If cel.Value = "" Then
            cel.EntireRow.Hidden = True
        End If
    Next cel
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Got a run error at:
LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
 
Upvote 0
I think that it would be easier to help and test possible solutions if I could work with your actual file which includes any macros you are currently using. Perhaps you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Include a detailed explanation of what you would like to do using a few examples from your data and referring to specific cells, rows, columns and worksheets. If the workbook contains confidential information, you could replace it with generic data.
 
Upvote 0
I can't see how any cell in column A of the "Summary" sheet will ever be blank. When you put a check mark beside a product in the List sheet, the product is added to the Summary sheet. When you un-check the product in List, it is deleted form the Summary sheet. When will any cell in column A of the "Summary" sheet be blank?
 
Upvote 0
Yes, the evaluated value in Row A of the "Summary" sheet returns "" if true. I assumed this was a blank cell. What's weird is that it works when using the SelectChange event but not the Change or Calculate event. Can you offer any other ideas or options?
 
Upvote 0
This macro works for me.
Code:
Private Sub Worksheet_Calculate()
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Dim bottomA As Long, cel As Range, desWS As Worksheet
    Set desWS = Sheets("Summary")
    bottomA = desWS.Range("A" & desWS.Rows.Count).End(xlUp).Row
    On Error GoTo errHandler
    desWS.Cells.EntireRow.Hidden = False
    For Each cel In desWS.Range("A5:A" & bottomA - 1)
        If cel.Value = "" Then
            cel.EntireRow.Hidden = True
        End If
    Next cel
errHandler:
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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