#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default HIDING ROWS

H
I am finding difficulties to write a macro to hide rows if all their cells are empty
I have a workbook with 500 rows and 20 columns. I would like to have the flexibility to print a given section of rows, say rows 20 to 150, provided one of the cells in the 20 columns has a value in it either a number or text.
Rows which have all cells empty across the 20 columns not to be printed.
Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default HIDING ROWS

Try something like this
It will check all columns this example not 20.
I don't know if that is a problem???

Private Sub Test()
Dim r As Long
Application.ScreenUpdating = False
With Worksheets("Sheet1")
For r = .UsedRange.Rows(.UsedRange.Rows.Count).Row To 1 Step -1
If Application.CountA(.Rows(r)) = 0 Then
.Rows(r).Hidden = True
End If
Next
End With
Application.ScreenUpdating = True
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"ANDREWS" wrote in message ...
Hi
I am finding difficulties to write a macro to hide rows if all their cells are empty.
I have a workbook with 500 rows and 20 columns. I would like to have the flexibility to print a given section of rows, say

rows 20 to 150, provided one of the cells in the 20 columns has a value in it either a number or text.
Rows which have all cells empty across the 20 columns not to be printed.
Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default HIDING ROWS

Thanks

It works. The problem is that my first column has data, something which i did not mentioned earlier sorry about this. So my problem still remains.

Thanks


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default HIDING ROWS

Try this then for checking column 2 to 20

Sub Test()
Dim r As Long
Application.ScreenUpdating = False
With Worksheets("Sheet1")
For r = .UsedRange.Rows(.UsedRange.Rows.Count).Row To 1 Step -1
If Application.CountA(Range(.Cells(r, 2), .Cells(r, 20))) = 0 Then
.Rows(r).Hidden = True
End If
Next
End With
Application.ScreenUpdating = True
End Sub


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"andrews" wrote in message ...
Thanks

It works. The problem is that my first column has data, something which i did not mentioned earlier sorry about this. So my

problem still remains.

Thanks




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default HIDING ROWS

Hi andrews

I see I forgot a dot
Add a dot before Range to be sure it will use Worksheets("Sheet1")

If Application.CountA(.Range(.Cells(r, 2), .Cells(r, 20))) = 0 Then


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Ron de Bruin" wrote in message ...
Try this then for checking column 2 to 20

Sub Test()
Dim r As Long
Application.ScreenUpdating = False
With Worksheets("Sheet1")
For r = .UsedRange.Rows(.UsedRange.Rows.Count).Row To 1 Step -1
If Application.CountA(Range(.Cells(r, 2), .Cells(r, 20))) = 0 Then
.Rows(r).Hidden = True
End If
Next
End With
Application.ScreenUpdating = True
End Sub


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"andrews" wrote in message ...
Thanks

It works. The problem is that my first column has data, something which i did not mentioned earlier sorry about this. So my

problem still remains.

Thanks








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default HIDING ROWS

Thanks Ro
It works perfec
thanks agai
andrew

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
Color alternate rows when after hiding selected rows Monk[_2_] Excel Worksheet Functions 6 June 7th 08 01:36 AM
Hiding Specific Rows Based on Values in Other Rows Chris Excel Worksheet Functions 1 November 2nd 06 08:21 PM
Hiding a button when hiding rows fergusor Excel Discussion (Misc queries) 2 August 10th 06 02:31 PM
Hiding Rows if the linked rows are blank KG Excel Discussion (Misc queries) 9 May 18th 05 02:32 AM
Copying Rows when hiding other rows Neutron1871 Excel Worksheet Functions 2 November 3rd 04 11:38 PM


All times are GMT +1. The time now is 02:09 AM.

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"