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
Bookmarks