Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Macro to hide multiple rows

Hi,

I am writing a macro at the moment that hides a row given
a certain criteria is met. However, at the moment I have
had to do this on a row by row basis:

e.g.
If A8 = Cat Then
Rows("8:8").Select
Selection.EntireRow.Hidden = True
End If
If A9 = Cat Then
Rows("9:9").Select
Selection.EntireRow.Hidden = True
End If

etc....

Is there a way to do this to a range of cells rather than
on a cell by cell basis?

Thanks heaps.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Macro to hide multiple rows

Hi

You will have to loop cell by cell for this, but it's easy and fast:

Sub test()
Dim R As Range, Cel As Range
Set R = Range("A1:M300")
For Each Cel In R
If Cel.Value = "Cat" Then _
Cel.EntireRow.Hidden = True
Next
End Sub

HTH. Best wishes Harald

"Minh" skrev i melding
...
Hi,

I am writing a macro at the moment that hides a row given
a certain criteria is met. However, at the moment I have
had to do this on a row by row basis:

e.g.
If A8 = Cat Then
Rows("8:8").Select
Selection.EntireRow.Hidden = True
End If
If A9 = Cat Then
Rows("9:9").Select
Selection.EntireRow.Hidden = True
End If

etc....

Is there a way to do this to a range of cells rather than
on a cell by cell basis?

Thanks heaps.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 618
Default Macro to hide multiple rows

alternatively, you might want to look into using filtering for this ... if
you use the macro recorder and data / autofilter .. and use the custom
option to display only those rows not equal to cat - it might give you what
you want.

Cheers
JulieD

"Harald Staff" wrote in message
...
Hi

You will have to loop cell by cell for this, but it's easy and fast:

Sub test()
Dim R As Range, Cel As Range
Set R = Range("A1:M300")
For Each Cel In R
If Cel.Value = "Cat" Then _
Cel.EntireRow.Hidden = True
Next
End Sub

HTH. Best wishes Harald

"Minh" skrev i melding
...
Hi,

I am writing a macro at the moment that hides a row given
a certain criteria is met. However, at the moment I have
had to do this on a row by row basis:

e.g.
If A8 = Cat Then
Rows("8:8").Select
Selection.EntireRow.Hidden = True
End If
If A9 = Cat Then
Rows("9:9").Select
Selection.EntireRow.Hidden = True
End If

etc....

Is there a way to do this to a range of cells rather than
on a cell by cell basis?

Thanks heaps.





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
How do I hide multiple rows under one row IN EXCEL? STEVEN Excel Worksheet Functions 3 May 7th 10 04:15 AM
Macro code to hide rows and not calculate hidden rows bradmcq Excel Discussion (Misc queries) 0 September 1st 09 12:38 AM
hide rows with macro Macro to hide rows in spreadwsheet Excel Discussion (Misc queries) 3 May 12th 05 05:02 PM
macro to hide rows david Excel Discussion (Misc queries) 3 April 8th 05 03:25 PM
Macro to hide rows Jeffrey Marcellus Excel Programming 0 September 5th 03 07:09 PM


All times are GMT +1. The time now is 04:54 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"