Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Delete Entire Row - Date

Column G & H contain Dates. I would like to run a macro that deletes the
entire row where the date in column G "or" H is greater than today().
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Delete Entire Row - Date

This should be close to what you want...

Sub DeleteRows()
Dim wks As Worksheet
Dim rngToSearch As Range
Dim rngCurrent As Range
Dim rngToDelete As Range

Set wks = ActiveSheet
Set rngToSearch = Range(wks.Range("G2"), wks.Range("G65536").End(xlUp))
For Each rngCurrent In rngToSearch
If rngCurrent.Value Date Or rngCurrent.Offset(0, 1).Value Date
Then
If rngToDelete Is Nothing Then
Set rngToDelete = rngCurrent
Else
Set rngToDelete = Union(rngToDelete, rngCurrent)
End If
End If
Next rngCurrent
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete

End Sub
--
HTH...

Jim Thomlinson


"Matt Cromer" wrote:

Column G & H contain Dates. I would like to run a macro that deletes the
entire row where the date in column G "or" H is greater than today().

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Delete Entire Row - Date

Jim -

I am getting an compile error when I paste this in. The error is on these
lines

If rngCurrent.Value Date Or rngCurrent.Offset(0, 1).Value Date
Then

Do you have any idea what would cause this?

Thanks for your help

"Jim Thomlinson" wrote:

This should be close to what you want...

Sub DeleteRows()
Dim wks As Worksheet
Dim rngToSearch As Range
Dim rngCurrent As Range
Dim rngToDelete As Range

Set wks = ActiveSheet
Set rngToSearch = Range(wks.Range("G2"), wks.Range("G65536").End(xlUp))
For Each rngCurrent In rngToSearch
If rngCurrent.Value Date Or rngCurrent.Offset(0, 1).Value Date
Then
If rngToDelete Is Nothing Then
Set rngToDelete = rngCurrent
Else
Set rngToDelete = Union(rngToDelete, rngCurrent)
End If
End If
Next rngCurrent
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete

End Sub
--
HTH...

Jim Thomlinson


"Matt Cromer" wrote:

Column G & H contain Dates. I would like to run a macro that deletes the
entire row where the date in column G "or" H is greater than today().

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
Delete an entire row One-Leg Excel Discussion (Misc queries) 13 November 11th 08 08:27 PM
Delete entire row if David T Excel Discussion (Misc queries) 2 December 6th 06 10:14 PM
Delete Entire Row Tony P.[_3_] Excel Programming 3 May 18th 05 09:58 PM
macro to find date format in a cell and delete that entire row vikram Excel Programming 8 April 30th 04 06:00 PM
Delete Entire Row. Sam Excel Programming 5 December 21st 03 05:56 AM


All times are GMT +1. The time now is 07:24 PM.

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

About Us

"It's about Microsoft Excel"