View Single Post
  #11 (permalink)  
Old 12-07-09, 06:35
Colin Legg Colin Legg is offline
Registered User
 
Join Date: Sep 2008
Location: London, UK
Posts: 495
In that case we need the Worksheet_Change event handler.

Right click on the worksheet tab and choose View Code. This will open up the worksheet's class module in the VBE. Add in this code:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Const strMATRIX As String = "C4:G6", strFORMULAS As String = "B12:B34"
    Dim rngCell As Range
    
    On Error GoTo ErrorHandler
    
    'was a cell in the matrix changed?
    If Not Intersect(Target, Range(strMATRIX)) Is Nothing Then
        Application.ScreenUpdating = False
        
        'calculate the formula range in case user has calcs set to manual
        Range(strFORMULAS).Calculate
        
        For Each rngCell In Range(strFORMULAS).Cells
            rngCell.EntireRow.Hidden = (LenB(rngCell.Value) = 0)
        Next rngCell
    End If
    
CleanUp:
    Application.ScreenUpdating = True
    Exit Sub

ErrorHandler:
    MsgBox "error number: " & Err.Number & vbNewLine & "error message: " & Err.Description
    Resume CleanUp
End Sub
Rather than using string constants for the two ranges you could use named ranges.

Hope that helps...
__________________
Colin

RAD Excel Blog

Other tutorials:
Array Formulas | Deleting Rows with VBA
Reply With Quote