Clear and Hide Empty Rows

User avatar
Joseph
3StarLounger
Posts: 206
Joined: 31 Dec 2010, 22:23
Location: Columbia Falls, MT

Clear and Hide Empty Rows

Post by Joseph »

Looking for a macro to do the following.

In Sheet1 Change Event
Look in Range (a6:a50)
If value is ""
Clear existing data in Row, from Column B to P.
Then Hide entire row.

Thanks.

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Clear and Hide Empty Rows

Post by HansV »

This code goes into the worksheet module:

Code: Select all

Private Sub Worksheet_Change(ByVal Target As Range)
  Dim rng As Range
  If Not Intersect(Range("A6:A50"), Target) Is Nothing Then
    Application.EnableEvents = False
    For Each rng In Intersect(Range("A6:A50"), Target)
      If rng.Value = "" Then
        rng.Offset(0, 1).Resize(1, 15).ClearContents
        rng.EntireRow.Hidden = True
      End If
    Next rng
    Application.EnableEvents = True
  End If
End Sub
Best wishes,
Hans

User avatar
Joseph
3StarLounger
Posts: 206
Joined: 31 Dec 2010, 22:23
Location: Columbia Falls, MT

Re: Clear and Hide Empty Rows

Post by Joseph »

Perfect!! Works mint, thanks Hans.