Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Hiding rows based on a date function

I have a spread sheet which can vary from 8k to 12k lines long.

Row 1 contains header information.

Column Y can contain either blank cells, or cells with dates.

Excel 2003.

I need to run through all the rows, look at the value in column Y, and
determine if it is more than 100 days from todays date. "today" meaning
whatever the date is when the macro is run. If the date in Y is more than 100
days from todays date, I need to hide the entire row.

Can anybody provide help with this?

Many thanks in advance!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Hiding rows based on a date function

Hi,

You don't say whether it's 100 days in the future or the past so this
assumes the future. Right click your sheet tab, view code and paste this in
and run it.

Sub Marine()
Dim MyRange, MyRange1 As Range
lastrow = Cells(Rows.Count, "Y").End(xlUp).Row
Set MyRange = Sheets("Sheet1").Range("Y2:Y" & lastrow)
For Each c In MyRange
If c.Value Now + 100 Then 'Change to suit
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.EntireRow.Hidden = True
End If
End Sub

Mike

"Melvin Purvis" wrote:

I have a spread sheet which can vary from 8k to 12k lines long.

Row 1 contains header information.

Column Y can contain either blank cells, or cells with dates.

Excel 2003.

I need to run through all the rows, look at the value in column Y, and
determine if it is more than 100 days from todays date. "today" meaning
whatever the date is when the macro is run. If the date in Y is more than 100
days from todays date, I need to hide the entire row.

Can anybody provide help with this?

Many thanks in advance!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Hiding rows based on a date function

I left the sheet range in use this instead

Sub Marine()
Dim MyRange, MyRange1 As Range
lastrow = Cells(Rows.Count, "Y").End(xlUp).Row
Set MyRange = Sheets("Sheet1").Range("Y2:Y" & lastrow)
For Each c In MyRange
If c.Value Now + 100 Then 'Change to suit
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.EntireRow.Hidden = True
End If
End Sub

Mike

"Mike H" wrote:

Hi,

You don't say whether it's 100 days in the future or the past so this
assumes the future. Right click your sheet tab, view code and paste this in
and run it.

Sub Marine()
Dim MyRange, MyRange1 As Range
lastrow = Cells(Rows.Count, "Y").End(xlUp).Row
Set MyRange = Sheets("Sheet1").Range("Y2:Y" & lastrow)
For Each c In MyRange
If c.Value Now + 100 Then 'Change to suit
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.EntireRow.Hidden = True
End If
End Sub

Mike

"Melvin Purvis" wrote:

I have a spread sheet which can vary from 8k to 12k lines long.

Row 1 contains header information.

Column Y can contain either blank cells, or cells with dates.

Excel 2003.

I need to run through all the rows, look at the value in column Y, and
determine if it is more than 100 days from todays date. "today" meaning
whatever the date is when the macro is run. If the date in Y is more than 100
days from todays date, I need to hide the entire row.

Can anybody provide help with this?

Many thanks in advance!


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Hiding rows based on a date function


Try this:

Sub hide_rows()
Dim i As Long
For i = Range("Y" & Rows.Count).End(xlUp).Row To 2 Step -1
If Range("Y" & i).Value < "" And Range("Y" & i) <= Date - 100 Then
Range("Y" & i).EntireRow.Hidden = True
End If
Next i
End Sub


--
Breakfast Guy

Regards,
Breakfast Guy
Forum Moderator
www.thecodecage.com
------------------------------------------------------------------------
Breakfast Guy's Profile: http://www.thecodecage.com/forumz/member.php?userid=5
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=23938

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default Hiding rows based on a date function

Just a note on whether the 100 days is in the past or in the future. If in
the past, both suggestions will work fine. But for in the future, all the
rows would need to be unhidden first, so that those rows that have been
previously hidden as over 100 days, can be retested.

Mike F
"Breakfast Guy" wrote in message
...

Try this:

Sub hide_rows()
Dim i As Long
For i = Range("Y" & Rows.Count).End(xlUp).Row To 2 Step -1
If Range("Y" & i).Value < "" And Range("Y" & i) <= Date - 100 Then
Range("Y" & i).EntireRow.Hidden = True
End If
Next i
End Sub


--
Breakfast Guy

Regards,
Breakfast Guy
Forum Moderator
www.thecodecage.com
------------------------------------------------------------------------
Breakfast Guy's Profile:
http://www.thecodecage.com/forumz/member.php?userid=5
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=23938



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 based value of cell within row Legion_c18 Excel Discussion (Misc queries) 0 February 22nd 08 06:01 AM
Hiding Specific Rows Based on Values in Other Rows Chris Excel Worksheet Functions 1 November 2nd 06 08:21 PM
Hiding rows based on a value John Excel Discussion (Misc queries) 1 July 2nd 05 08:44 PM
Hiding Rows Based on Percentile Jonny Excel Discussion (Misc queries) 1 March 31st 05 01:10 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:49 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"