Can you conditionally hide a cell?

G

Guest

Guest
I want to use an IF command to hide a cell if it has no value as a way of consolidating my list. I've tried conditional formating but can't find a "hide" selection. Can it be written in code? Any suggestions would be appreciated.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
This is the ultimate solution, I think :)
Just enter the correct range to check.

<pre>
Private Sub Worksheet_Change(ByVal Target As Excel.Range)

Dim CheckRange As Range
'range to check
Set CheckRange = Range("a1:d20")
CheckColMin = CheckRange.Column
CheckRowMin = CheckRange.Row
CheckColMax = CheckRange.Column + CheckRange.Columns.Count - 1
CheckRowMax = CheckRange.Row + CheckRange.Rows.Count - 1

'check if the changed cell is a part of the range to check
If Target.Column >= CheckColMin And Target.Column <= CheckColMax _
And Target.Row >= CheckRowMin And Target.Row <= CheckRowMax Then

Rows(Target.Row).Select
'does the selection contains alfanumeric items ?
If Application.CountA(Selection) = Application.Count(Selection) Then
'no alfanumeric items, check now the values
If Application.Sum(Selection) = 0 Then
'only 0 of empty cells found, hide the row now
Rows(Target.Row).EntireRow.Hidden = True
End If
End If
Target.Select
End If

End Sub
</pre>
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,605
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top