+ Reply to Thread
Results 1 to 1 of 1

Auto Hide or Unhide rows.

Hybrid View

  1. #1
    Registered User
    Join Date
    10-19-2009
    Location
    Arkansas
    MS-Off Ver
    Excel 2003
    Posts
    1

    Auto Hide or Unhide rows.

    For starters, I am completely new to VBA so please don't assume that i know anything about it.
    I am building a report that up to 40 people will be using. It's 3 columns wide and currently 155 rows deep. Some of the rows have all 3 cells merged and some have 2 merged and some have none merged. It is full of drop down list and references to cells on other sheets. Several of the cells/rows are for the people filling out the report to type explinations of the days events. I have managed to piece together a macro that will automatically change the row height to accomidate for text that is wider than the cell. See macro below....

    There are several sections to the report. Each section has a row of protected text explaining what information should be entered into the next section of rows. I have built 10 blank rows for this information to be recorded in but, I hide all but 1 of them to keep the length as short as necessary. Now what I would like to do is make the macro automatically hide or unhide rows so that if the person filling out the report uses the 2 unhidden cells, the next cell unhides. Also if a cell of text is deleted, I would like to hide it so that I never have more than 1 empty cell/row per section.

    I am attaching a fake example that will hopefully explain what I'm trying to do.
    Report.xls
    If someone types text in row 23, I would like to have row 24 unhide. If someone then delets the text in row 23, I would like to have 24 hide. so on and so forth...

    Any and all help would be appreciated.
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim CurrentRowHeight As Single, MergedCellRgWidth As Single
    Dim CurrCell As Range
    Dim ActiveCellWidth As Single, PossNewRowHeight As Single
    If Target.MergeCells Then
    With Target(1, 1).MergeArea
    If .Rows.Count = 1 And .WrapText = True Then
        Application.ScreenUpdating = False
        CurrentRowHeight = .RowHeight
        ActiveCellWidth = Target(1, 1).ColumnWidth
        For Each CurrCell In .Cells
            MergedCellRgWidth = CurrCell.ColumnWidth + MergedCellRgWidth
        Next
        .MergeCells = False
        .Cells(1).ColumnWidth = MergedCellRgWidth
        .EntireRow.AutoFit
        PossNewRowHeight = .RowHeight
        .Cells(1).ColumnWidth = ActiveCellWidth
        .MergeCells = True
            .RowHeight = IIf(CurrentRowHeight >= StandardHeight, _
        PossNewRowHeight, StandardHeight)
    
        
        
    
       
    End If
    End With
    End If
    Application.ScreenUpdating = True
    End Sub
    Last edited by Leith Ross; 10-19-2009 at 08:02 PM. Reason: Added Code Tags

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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