select, copy and paste range of rows based on a date value in a cell in a sorted by date list
I need some help with some VBA in Excel to find a particular cell value (i.e today's date) and then based on that criteria select, copy and paste a range of rows into another worksheet based on the criteria that they are in the past or future. My worksheet is sorted ASC by date and have read a number of posts simillar to this problem but I didn't solve on my own so don't know if my problem is lack of expertise in working with dates, or that all the threads I read had slightly different requirements.
A sample of the source worksheet looks like this;
givenName RegistrationStartDate
Kirstie 1/07/2010
Momena 12/01/2011
Seyedkazem 18/01/2011
Christie 3/02/2011
Jakub 8/02/2011
Steven 11/07/2011
Patrina 13/07/2011
Gregory 14/07/2011
Fatima 15/07/2011
Thomas 18/07/2011
Ala **19/07/2011**
Anne 开发者_高级运维 31/07/2011
Umair 1/08/2011
Laura 2/08/2011
And I need help with VBA to find today's date 19/07/2011 and paste this into a 'in the past' worksheet;
givenName RegistrationStartDate
Kirstie 1/07/2010
Momena 12/01/2011
Seyedkazem 18/01/2011
Christie 3/02/2011
Jakub 8/02/2011
Steven 11/07/2011
Patrina 13/07/2011
Gregory 14/07/2011
Fatima 15/07/2011
Thomas 18/07/2011
and 'in the future' worksheet
givenName RegistrationStartDate
Anne 31/07/2011
Umair 1/08/2011
Laura 2/08/2011
I guess what might have been adding to my grief is that I specifically don't need any rows with today's date. Once I get this sorted out I will be adding logic to the 'what date is it now' criteria (i.e 28 days before and after today's date) and copy/pasting rows based on that. I think if some kind guru can help me with the above, I should be okay from there.
Best Regards
Larry
So to answer your question, the function to get the current date (i.e. the system date which hopefully is the same), you use the Date
function.
Now you process he list and compare each date with the system date;
- dates < sysdate are past
- dates > sysdate are future
- dates = sysdate are ignored
if your dates in the table contain time information, you must use Int(yourtabledate)
to get rid of the time, because 02.08.2011 08:12 > 02.08.2011
(with implicit time 00:00
) and would therefore go to future which you don't want.
For ther rest ... if you don't know how to fomulate a loop across a table in VBA, post a specific question.
Cheers Mike
精彩评论