PDA

View Full Version : VBA macro to hide rows based on cell value



Djani
05-23-2016, 12:20 AM
Dear all,

I have found a working code to hide rows based on a blank cell value, but I don't know how to modify it to my needs:



Sub HideRows()
Application.ScreenUpdating = False
For Each cl In Range("J6:J78")
If cl = "" And (cl.Row - 3) Mod 14 > 1 Then cl.EntireRow.Hidden = True
Next cl
End Sub



I want the macro to check the values in column J6:J78 and hide the entire row when it is a blank. However, in the picture below there are several empty rows in-between the tables. I don't want the macro to hide these, but keep them as it is.

http://i63.tinypic.com/2qxx21l.png

There are always 3 rows in-between tables as you can see in the above-mentioned picture.

Can anyone please help me out?

Many thanks in advance.

snb
05-23-2016, 01:20 AM
Or you want to hide the rows of 'empty' cells or you don't want that. There's no in between.
Please do not post pictures, this is an Excel forum. Upload Excelfiles instead.

Djani
05-23-2016, 01:29 AM
@snb, thanks for mentioning. I have put an example in the attachments.
I would like the macro to hide specific rows by checking column J on blank (="") values.

snb
05-23-2016, 01:36 AM
Waarom stel je de vraag niet in Helpmij.nl ?

Aussiebear
05-23-2016, 03:19 AM
Why not name the tables and the check the value per table?

p45cal
05-23-2016, 11:44 AM
Sub HideRows()
Application.ScreenUpdating = False
For Each cl In Range("J6:J13,J19:J26,J32:J39,J45:J52,J58:J65,J71:J78")
If cl = "" Then cl.EntireRow.Hidden = True
Next cl
End Sub

snb
05-23-2016, 12:02 PM
Sub M_snb()
c00 = sheet11.Columns(10).SpecialCells(-4123).Address

With sheet11.Cells(1, 10).Resize(Sheet11.UsedRange.Rows.Count)
.Value = .Value
End With

sheet11.Range(c00).SpecialCells(4).EntireRow.Hidden = True
End Sub

If you use another formula in column J

e.g If(K6="",false,K6)

You can use the 1-liner:


Sub M_snb()
columns(10).specialcells(-4123,4).entirerow.hidden=true
End Sub