Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
tig tig is offline
external usenet poster
 
Posts: 10
Default Hiding Rows in a Range based on column A value

I've been rummaging through the posts regarding finding the last row in
a range. They don't quite get me what I need. My ultimate goal is to
created a sub that will hide all rows with the value of "1" in column
A. Without creating a loop for the entire worksheet I want to limit
the loop to a named range, let's say "print_range". To do that I need
to be able to identify the last row of the named range. I don't think
that the Count property will give me the last row if the range doesn't
begin in row 1.

Let's say my named range is from A5:Z999.

Any ideas or insights would be greatly appreciated.

TIA

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Hiding Rows in a Range based on column A value

Hi,
Why not ...

For each cell in Range("Print_Range")
If cell.value = 1 then
cell.entirerow.hidden=true
end if
next cell

"tig" wrote:

I've been rummaging through the posts regarding finding the last row in
a range. They don't quite get me what I need. My ultimate goal is to
created a sub that will hide all rows with the value of "1" in column
A. Without creating a loop for the entire worksheet I want to limit
the loop to a named range, let's say "print_range". To do that I need
to be able to identify the last row of the named range. I don't think
that the Count property will give me the last row if the range doesn't
begin in row 1.

Let's say my named range is from A5:Z999.

Any ideas or insights would be greatly appreciated.

TIA


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Hiding Rows in a Range based on column A value

you can try this method:

Sub hide()
Dim r As Range
For Each r In ActiveSheet.Range("tst").Rows
If r.Cells(1, 1) = "1" Then r.Hidden = True
Next r
Set r = Nothing
End Sub


--
HTHs Martin


"tig" wrote:

I've been rummaging through the posts regarding finding the last row in
a range. They don't quite get me what I need. My ultimate goal is to
created a sub that will hide all rows with the value of "1" in column
A. Without creating a loop for the entire worksheet I want to limit
the loop to a named range, let's say "print_range". To do that I need
to be able to identify the last row of the named range. I don't think
that the Count property will give me the last row if the range doesn't
begin in row 1.

Let's say my named range is from A5:Z999.

Any ideas or insights would be greatly appreciated.

TIA


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Hiding Rows in a Range based on column A value

Hi,
Ignore my last post as your "print_range" is multiple columns UNLESS
you know ONLY column A will contain 1 or "1".

"Toppers" wrote:

Hi,
Why not ...

For each cell in Range("Print_Range")
If cell.value = 1 then
cell.entirerow.hidden=true
end if
next cell

"tig" wrote:

I've been rummaging through the posts regarding finding the last row in
a range. They don't quite get me what I need. My ultimate goal is to
created a sub that will hide all rows with the value of "1" in column
A. Without creating a loop for the entire worksheet I want to limit
the loop to a named range, let's say "print_range". To do that I need
to be able to identify the last row of the named range. I don't think
that the Count property will give me the last row if the range doesn't
begin in row 1.

Let's say my named range is from A5:Z999.

Any ideas or insights would be greatly appreciated.

TIA


  #5   Report Post  
Posted to microsoft.public.excel.programming
tig tig is offline
external usenet poster
 
Posts: 10
Default Hiding Rows in a Range based on column A value

Martin,

Thank you for the reply. The method you gave me works pretty well. So
I'm a little better off than I was earlier. The only problem is that
the range is usually over 1000 rows. So it takes quite a while to go
through the loop.

Any ideas on speeding it up?? One thing I thought of was to create a
named range with the rows with column A = 1, then I could just do
Range("test").Rows.Hidden = True.

My problem is I'm not sure if I can programmatically populate a named
range in a loop like that. And who knows, it might not even be much
faster.

Let me know if you have any further insights.

Thanks again.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Hiding Rows in a Range based on column A value

Why Not Filter the column

Sub Hide_with_Autofilter()
Dim HideValue As String
Dim rng As Range

HideValue = "ron"
' This will hide the rows with "ron" in the Range("A1:A100")
With ActiveSheet
.Range("A1:A100").AutoFilter Field:=1, Criteria1:=HideValue
With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0

End With
.AutoFilterMode = False
End With

If Not rng Is Nothing Then rng.EntireRow.Hidden = True

End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"tig" wrote in message oups.com...
Martin,

Thank you for the reply. The method you gave me works pretty well. So
I'm a little better off than I was earlier. The only problem is that
the range is usually over 1000 rows. So it takes quite a while to go
through the loop.

Any ideas on speeding it up?? One thing I thought of was to create a
named range with the rows with column A = 1, then I could just do
Range("test").Rows.Hidden = True.

My problem is I'm not sure if I can programmatically populate a named
range in a loop like that. And who knows, it might not even be much
faster.

Let me know if you have any further insights.

Thanks again.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Hiding Rows in a Range based on column A value

There is one tweek that you can play around with in VBA/excel:

at the start of the sub include:

Application.ScreenUpdating = false


and at the end of the sub include (if you are in 2002+ then it is very
important to include this):

Application.ScreenUpdating = true

Excel before 2002 automatically turned screenupdating back on at the end of
macro now it does not and if you halt your code or you get exceptions you
need to write a little macro that will turn it back on and keep it in your
personal:

sub TurnScreenUpdatingOn()
Application.ScreenUpdating = true
end sub

The other area is in code optimisation. Display your code I will review it
or someone else will if I've gone to bed. LOL 21:30 here.LOL

--
HTHs Martin


"tig" wrote:

Martin,

Thank you for the reply. The method you gave me works pretty well. So
I'm a little better off than I was earlier. The only problem is that
the range is usually over 1000 rows. So it takes quite a while to go
through the loop.

Any ideas on speeding it up?? One thing I thought of was to create a
named range with the rows with column A = 1, then I could just do
Range("test").Rows.Hidden = True.

My problem is I'm not sure if I can programmatically populate a named
range in a loop like that. And who knows, it might not even be much
faster.

Let me know if you have any further insights.

Thanks again.


  #8   Report Post  
Posted to microsoft.public.excel.programming
tig tig is offline
external usenet poster
 
Posts: 10
Default Hiding Rows in a Range based on column A value

Martin,

I tried the ScreenUpdatingOn you suggested. That made it a little
faster. I'll attach my code in case you can't sleep. :-) or someone
else wants a crack at it.

In the mean time I'm going to try to incorporate Ron's Filter idea.

Thank you both for your help so far.

Sub ad_hide()

Application.ScreenUpdating = False

Dim r As Range
For Each r In ActiveSheet.Range("Print_area").Rows
If IsNumeric(r.Cells(1, 1 - 1)) Then
If r.Cells(1, 1 - 1) = 1 Then
r.Hidden = False
Else
r.Hidden = True
End If
Else
r.Hidden = True
End If
Next r
Set r = Nothing

Application.ScreenUpdating = True

End Sub

  #9   Report Post  
Posted to microsoft.public.excel.programming
tig tig is offline
external usenet poster
 
Posts: 10
Default Hiding Rows in a Range based on column A value

Thanks for the reply Martin. I working in Excel 97 right now. Based
on your notes, it may not make a difference. Right?

My code is at the top of the post.

Thanks again.

  #10   Report Post  
Posted to microsoft.public.excel.programming
tig tig is offline
external usenet poster
 
Posts: 10
Default Hiding Rows in a Range based on column A value

Sorry Martin. I replied to the wrong post. Duh!!

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
Hiding rows in a range based on TRUE/FALSE value in each row michaelberrier Excel Discussion (Misc queries) 1 December 28th 06 10:33 PM
Hiding Specific Rows Based on Values in Other Rows Chris Excel Worksheet Functions 1 November 2nd 06 08:21 PM
Need help hiding/unhiding column based on autofilter selection in a different column kcleere Excel Programming 1 January 23rd 06 06:21 AM
Hiding rows based on a value John Excel Discussion (Misc queries) 1 July 2nd 05 08:44 PM
Hiding rows based on date Steve Excel Worksheet Functions 2 November 1st 04 02:30 PM


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