Hide Rows

J

jjj

Hi,

I've been working on this for a few hours and am finding this one to b
a difficult one.

How can I write a formula or some code that will hide rows based o
values?

Example:
If in Row 1, cells F1 and J1 contained zero, then hide the whole row
(This would need to be done for multiple rows i.e all rows where F an
J columns contained zeros)

Please help.

Thank You
 
G

Guest

You can't do it with formulas, you need VBA code. This example will do it as
the worksheet changes, not a macro to run to hide all rows at once:
right-click the sheet tab, select View Code, enter this code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 6 And Target.Column <> 10 Then Exit Sub
n = Target.Row
If Cells(n, 6).Value = 0 _
And Cells(n, 10).Value = 0 _
And Len(Cells(n, 6).Value) = 1 _
And Len(Cells(n, 10).Value) = 1 Then Rows(n).Hidden = True
End Sub
 
J

Jules

I'd use a variation on code below...

Dim rowno As Integer

For rowno = 1 To 1000

If Range("A" & rowno).value = "" Then
Exit For

Elseif range("A" & rowno).value = 0 then

Rows(rowno).Select

Selection.EntireRow.Hidden = True

else
endif

Next
 

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