Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Zak Zak is offline
external usenet poster
 
Posts: 144
Default Date ranges in macros

Hi, i asked this question in a previous thread but it still hasnt been
answered and a couple of my other questions have so was wondering whether i
need to re-submit.

i want to write a macro that will recognise that the date in column x is
beyond
todays date and then delete the rows.

So, if the date in column X is beyond/greater than todays date (and this date
should be the current day) then the rows should be deleted.

thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Date ranges in macros

Hi Zak,

This routine should do your job. The dates to test are in column x:

Sub DeleteRowsbyDate()
For Each cll In Range([x1], [x1].End(xlDown))
If IsDate(cll) And cll Now() Then _
cll.EntireRow.Delete
Next
End Sub

CAUTION!! Use with care... you cannot undo these changes.

regards,
Lazzzx


"Zak" skrev i meddelelsen
...
Hi, i asked this question in a previous thread but it still hasnt been
answered and a couple of my other questions have so was wondering whether
i
need to re-submit.

i want to write a macro that will recognise that the date in column x is
beyond
todays date and then delete the rows.

So, if the date in column X is beyond/greater than todays date (and this
date
should be the current day) then the rows should be deleted.

thanks.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default Date ranges in macros

hi
I think your have left out a lot for someone to give a good reply but i will
make some guesses.
assume that you are in a loop, with the key being column x.....
If activecell.Value Date Then
activecell.EntireRow.Delete shift:=xlUp
End If

Personally i don't like using activecell in a loop. it requires select which
slows things down. i prefer using variables. something like this....
Sub test1()
Dim r As Range
Dim rd As Range
Set r = Range("X2") 'assume a header
Do While Not IsEmpty(r)
Set rd = r.Offset(1, 0)
If r.Value Date Then
r.EntireRow.Delete shift:=xlUp
End If
Set r = rd 'move down one or next
Loop
End Sub

I'm using a do loop here because i'm dealing with an unknow ie(how may rows)
most programmers perfer the for next loop but each has it's purpose. that's
why vb has both. do loops can get out of control if not coded right ie run
away code. for next loop only do thing a certain number of times then quits
but you must find the limits to restrict it to.
for next loop
Sub test2()
Dim r As Range

lr = Cells(Rows.Count, "X").End(xlUp).Row 'finds the last row in data
Set r = Range("x2:x" & lr)

For Each cell In r
If cell.Value Date Then
cell.EntireRow.Delete
End If
Next cell

End Sub

hope this wild guessing is giving you ideas
regards
FSt1

"Zak" wrote:

Hi, i asked this question in a previous thread but it still hasnt been
answered and a couple of my other questions have so was wondering whether i
need to re-submit.

i want to write a macro that will recognise that the date in column x is
beyond
todays date and then delete the rows.

So, if the date in column X is beyond/greater than todays date (and this date
should be the current day) then the rows should be deleted.

thanks.

  #4   Report Post  
Posted to microsoft.public.excel.programming
Zak Zak is offline
external usenet poster
 
Posts: 144
Default Date ranges in macros

Thanks for all your guesses. Each one worked but the problem is when i ran
the macro i saw that it only deleted a few lines at a time. I had to run the
macro 3 times (clicked it 3 times) to get it to delete all the rows i wanted!

why is this happening? cant it delete everything with one click?

thanks.

"FSt1" wrote:

hi
I think your have left out a lot for someone to give a good reply but i will
make some guesses.
assume that you are in a loop, with the key being column x.....
If activecell.Value Date Then
activecell.EntireRow.Delete shift:=xlUp
End If

Personally i don't like using activecell in a loop. it requires select which
slows things down. i prefer using variables. something like this....
Sub test1()
Dim r As Range
Dim rd As Range
Set r = Range("X2") 'assume a header
Do While Not IsEmpty(r)
Set rd = r.Offset(1, 0)
If r.Value Date Then
r.EntireRow.Delete shift:=xlUp
End If
Set r = rd 'move down one or next
Loop
End Sub

I'm using a do loop here because i'm dealing with an unknow ie(how may rows)
most programmers perfer the for next loop but each has it's purpose. that's
why vb has both. do loops can get out of control if not coded right ie run
away code. for next loop only do thing a certain number of times then quits
but you must find the limits to restrict it to.
for next loop
Sub test2()
Dim r As Range

lr = Cells(Rows.Count, "X").End(xlUp).Row 'finds the last row in data
Set r = Range("x2:x" & lr)

For Each cell In r
If cell.Value Date Then
cell.EntireRow.Delete
End If
Next cell

End Sub

hope this wild guessing is giving you ideas
regards
FSt1

"Zak" wrote:

Hi, i asked this question in a previous thread but it still hasnt been
answered and a couple of my other questions have so was wondering whether i
need to re-submit.

i want to write a macro that will recognise that the date in column x is
beyond
todays date and then delete the rows.

So, if the date in column X is beyond/greater than todays date (and this date
should be the current day) then the rows should be deleted.

thanks.

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
Expanding ranges in macros Jeff Excel Discussion (Misc queries) 4 January 5th 09 10:16 PM
Selecting ranges in macros carl Excel Programming 1 July 17th 07 05:04 PM
using named ranges in macros Dave F Excel Discussion (Misc queries) 0 November 29th 06 05:13 PM
using named ranges in macros Dave F Excel Discussion (Misc queries) 0 November 29th 06 04:08 PM
Defining Ranges using macros bhussey[_3_] Excel Programming 5 May 18th 06 11:26 PM


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