+ Reply to Thread
Results 1 to 5 of 5

Auto hide blank rows

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-04-2013
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    122

    Auto hide blank rows

    Workbook attached

    I'm trying to build a products database, which does not need to be very sophisticated to be honest. I have separate sheets for separate sub categories and i want to update this as new products arise, no problem. Occasionally I am required to provide a product index of specific products supplied on a specific project.

    Before today, i had all of my 'sub categories' on one sheet from top to bottom and would simply hide all the rows that were either blank or did not contain a product that was used on a job, i would then print the remaining rows to create the bespoke project index before 'un-hiding' the rows. This has proved rather long winded.

    What i would like to do, if its even possible, is work my way through the sub categories sheets marking column E with an "x" or tick or "yes" if the product is to be included in the print copy and then once i've worked through all the sub categories sheets 'ticking' or marking all the appropriate products i can 'activate' the print copy sheet and it will auto populate the rows/ hide all unnecessary rows etc leaving me with a full list or index of only the products actually used. where this might get even trickier is that i need labelled 'dividing' rows between sub categories (shown in the workbook).

    I've begun working on this and tried to do this using some code (in the O&M print copy sheet) but it doesnt bunch up the data and leaves blank rows plus i don't know how to adapt the ranges either side of my 'dividing rows'.

    Am i missing something? or is this simply not possible to achieve?

    Your thoughts or advice is greatly recieved. xProduct index Master Forum example.xlsm

  2. #2
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Auto hide blank rows

    Do you still need assistance with this? If so, I have a question: Do you want the O&M Copy sheet sections to automatically adjust when parts are added to or deleted from the source sheets?
    Acts 4:12
    Salvation is found in no one else, for there is no other name under heaven given to mankind by which we must be saved.

  3. #3
    Registered User
    Join Date
    01-28-2014
    Location
    Schenectady, NY
    MS-Off Ver
    Office 365
    Posts
    65

    Re: Auto hide blank rows

    Put this code on your worksheet:
    Private Sub Worksheet_Activate()
    HideandUnhide
    End Sub
    Put this code in a module:

    Sub HideandUnhide()
    
     
     Dim hrange As Range
     Dim urange As Range
     
     'Unhide rows for new report
     Set urange = ActiveWorkbook.Worksheets("REPORTS").Range("Z5").Cells
     
     Range(urange).EntireRow.Hidden = False
     
     
     
     'Hide rows with no data
     Set hrange = ActiveWorkbook.Worksheets("REPORTS").Range("Z6").Cells
     
     Range(hrange).EntireRow.Hidden = True
     
     
     Range("B2:C2").Select
    
     
     End Sub
    ON the worksheet you're "ticking" off on, you'll need some sort of counter, like =Countif(Y:Y,"X"). In your "Z" column (you may need to adjust these), you'll need to determine "Unhide" range and "Hide" range. Unhide can be a static total range of your worksheet (like A1:A100). Your hide range will be dynamic, like ="A"&Z4&":A100" where Z4 = your count of x's + however many rows you need for headers.

    Hope this makes sense. I just built something VERY similar.

  4. #4
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Auto hide blank rows

    Put this in your worksheet area of the code:

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If UCase(Target) = "CLEAR" Then Range("E4:E" & Cells(Rows.Count, 1).End(xlUp).Row) = ChrW(9744): Cells.EntireRow.Hidden = False: Cancel = True: Exit Sub
    If Target = ChrW(9744) Then Target = ChrW(9745): Cancel = True: Exit Sub
    If Target = ChrW(9745) Then Target = ChrW(9744): Cancel = True: Exit Sub
    Dim cell As Range
    If UCase(Target) = "FILTER" Then
    Application.ScreenUpdating = False
    For Each cell In Range("E2:E" & Cells(Rows.Count, 1).End(xlUp).Row)
    If cell <> ChrW(9745) Then cell.EntireRow.Hidden = True
    Next cell
    Target = "Unfilter"
    Cancel = True
    Application.ScreenUpdating = True
    Exit Sub
    End If
    If UCase(Target) = "UNFILTER" Then Cells.EntireRow.Hidden = False: Target = "Filter": Cancel = True
    End Sub
    Write in any cell in row 1 (for example in D1) the word "Clear" and double click it.
    In column E, a bunch of 'checkboxes' will appear - double click them to toggle them.
    Write in any cell in row 1 (for example in E1) the word "Filter" and double click it.
    Only the 'checked' boxes will remain and the word 'Filter' changes to 'Unfilter'. Guess what that does :-)

    Enjoy.
    Last edited by JasperD; 04-13-2015 at 03:25 PM.
    Please click the * below if this helps

  5. #5
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Auto hide blank rows

    Please try the following:
    1. In each parts sheet, select cell A1 and under Alignment, unselect Wrap Text (needed for proper formatting by the code).
    2. Delete any worksheets other than the parts sheets and the product index sheet. If this is not desirable, a code adjustment will be needed.
    3. Replace the product index Worksheet_Activate code with the following:

    Private Sub Worksheet_Activate()
    Dim sh As Worksheet, rw As Long, endrw As Long, OMRw As Long
    
        If MsgBox("Rebuild Parts Index?", vbYesNo, "Parts Index") <> vbYes Then Exit Sub
        
        Application.ScreenUpdating = False
        rw = Cells.SpecialCells(xlCellTypeLastCell).Row
        Rows("2:" & rw).Delete
        OMRw = 2
        For Each sh In ActiveWorkbook.Sheets
            With sh
                If .Name <> ActiveSheet.Name Then
                    If .Range("E" & .Rows.Count).End(xlUp).Row > 2 Then ' There are included parts on this sheet
                        .Range("A1").Copy Cells(OMRw, 1) ' Section name
                        Range(Cells(OMRw, 1), Cells(OMRw, 3)).VerticalAlignment = xlCenter
                        Range(Cells(OMRw, 1), Cells(OMRw, 3)).MergeCells = True
                        .Range("A2:C2").Copy Cells(OMRw + 1, 1) ' Section headings
                        OMRw = OMRw + 2
        
                        endrw = .Range("A" & .Rows.Count).End(xlUp).Row
                        For rw = 3 To endrw
                            If .Cells(rw, 5).Value <> "" Then ' Selected part
                                .Range(.Cells(rw, 1), .Cells(rw, 3)).Copy Cells(OMRw, 1)
                                OMRw = OMRw + 1
                            End If
                        Next
                        OMRw = OMRw + 1
                    End If
                End If
            End With
        Next
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Can I auto-hide rows or auto-set row height?
    By Hambone70 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 07-03-2014, 01:25 AM
  2. Can I auto-hide rows or auto-set row height?
    By Hambone70 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-27-2014, 05:59 AM
  3. Can I auto-hide rows or auto-set row height?
    By Hambone70 in forum Excel General
    Replies: 2
    Last Post: 06-27-2014, 02:59 AM
  4. auto hide a row if the value of a cell is blank on a specific sheet.
    By russ8420 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-27-2012, 02:13 PM
  5. Hide Blank rows
    By Charity in forum Excel General
    Replies: 15
    Last Post: 11-23-2006, 08:20 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1