Macro to hide rows

L

lightbulb

I have formulas in consecutive rows, but I want to run a macro that will hide
the rows that equal 0, and if they change and don't equal 0, the row will
unhide. Is there a code for this? (I'm using Excel 2003)

Thanks!
 
L

Lars-Åke Aspelin

I have formulas in consecutive rows, but I want to run a macro that will hide
the rows that equal 0, and if they change and don't equal 0, the row will
unhide. Is there a code for this? (I'm using Excel 2003)

Thanks!


Try this:

Private Sub Worksheet_Change(ByVal Target As Range)
maxrownumber = 100
column_to_test = 1
For i = 1 To maxrownumber
If Cells(i, column_to_test).HasFormula Then
Rows(i).EntireRow.Hidden = (Cells(i, 1) = 0)
End If
Next i
End Sub

You can play with the maxrownumber and column_to_test to suit your
needs.

Hope this helps / Lars-Åke
 
L

Lars-Åke Aspelin

Try this:

Private Sub Worksheet_Change(ByVal Target As Range)
maxrownumber = 100
column_to_test = 1
For i = 1 To maxrownumber
If Cells(i, column_to_test).HasFormula Then
Rows(i).EntireRow.Hidden = (Cells(i, 1) = 0)
End If
Next i
End Sub

You can play with the maxrownumber and column_to_test to suit your
needs.

Hope this helps / Lars-Åke

Oops, forgot to change one of the 1's to column_to_test.


Private Sub Worksheet_Change(ByVal Target As Range)
maxrownumber = 100
column_to_test = 1
For i = 1 To maxrownumber
If Cells(i, column_to_test).HasFormula Then
Rows(i).EntireRow.Hidden = (Cells(i, column_to_test) = 0)
End If
Next i
End Sub
 
L

lightbulb

This did not work. In excel, I went to Tools-Macro-and named a new macro,
then I simply copy and pasted your macro into the Visual Basic code and it
did not work. Am I doing something wrong?
Thanks!
 
P

Peo Sjoblom

Right click the sheet tab where you want this macro and select view code,
paste it there

--


Regards,


Peo Sjoblom
 

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