How can i hide a row or delete

A

algebroni

Is there a way i can hide or delete a whole row if the sum of the cell is = 0
example if A5=0 delete or hide the whole row. Thanks
 
M

Mike

If A5 is zero then this will hide row 5

Private Sub Worksheet_Change(ByVal Target As Range)
If Cells(5, 1).Value = 0 Then
Rows("5:5").Select
Selection.EntireRow.Hidden = True
End If
End Sub
 
G

Gord Dibben

Functions can only return values, not make formatting changes.

Is the value in O5 the result of a formula in O5?

Change event code is not triggered by a formula-generated value being changed.

Only triggered when you actually Enter something in the cell.

Try this if a formula-generated value in O5

Private Sub Worksheet_Calculate()
On Error GoTo endit
Application.EnableEvents = False
With Me.Range("O5")
If (.Value) = 0 Then
.EntireRow.Hidden = True
Else: .EntireRow.Hidden = False
End If
End With
endit:
Application.EnableEvents = True
End Sub

This is sheet event code. Right-click on your sheet tab and "View Code".

Copy/paste into that sheet module.



Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top