Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default Hide row if cell is empty

On a button click I'd like to hide row 4 if a4 is empty. I'd like to this up
to row 20 if the correspondince cell to that row in column a is empty. Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Hide row if cell is empty

Sub HideRows()
range("A1:A20").Entirerow.Hidden = False
on Error resume Next
set rng = Range("A1:A20").specialCells(xlblanks)
On Error goto 0
if not rng is nothing then
rng.Entirerow.Hidden = True
End if
End Sub

Assume no merged cells.

--
Regards,
Tom Ogilvy


"Qaspec" wrote in message
...
On a button click I'd like to hide row 4 if a4 is empty. I'd like to this

up
to row 20 if the correspondince cell to that row in column a is empty.

Thanks.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Hide row if cell is empty

Hi,
The following code should work fine:
'---------------------------------------------------
Sub HideTheRows()
HideRowsForBlanks Range("A1:A20")
HideRowsForBlanks Range("A25:A30,A35")
End Sub

Sub HideRowsForBlanks(Rg As Range)
Dim cell As Range, rgToHide As Range

'build empty-cell range
For Each cell In Rg.Cells
If cell.Text = "" Then
If rgToHide Is Nothing Then
Set rgToHide = cell
Else
Set rgToHide = Application.Union(rgToHide, cell)
End If
End If
Next

'Hide
If Not rgToHide Is Nothing Then
rgToHide.EntireRow.Hidden = True
End If

End Sub
'------------------------------------------------
--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"Qaspec" wrote:

On a button click I'd like to hide row 4 if a4 is empty. I'd like to this up
to row 20 if the correspondince cell to that row in column a is empty. Thanks.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically hide a row if it is empty Vil Excel Discussion (Misc queries) 1 November 19th 08 11:10 AM
Hide the line when cell B is empty Christine Excel Discussion (Misc queries) 4 August 1st 08 05:25 PM
if cell empty hide row macro? Todd Excel Programming 2 June 18th 04 07:18 PM
Hide row with empty cells Trevor Shuttleworth Excel Programming 0 September 26th 03 10:13 PM
Hide row with empty cells Don Guillett[_4_] Excel Programming 0 September 26th 03 06:36 PM


All times are GMT +1. The time now is 11:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"