简体   繁体   English

select,根据日期排序列表中单元格中的日期值复制和粘贴行范围

[英]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 (ie 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.我需要一些关于 Excel 中的 VBA 的帮助,以找到特定的单元格值(即今天的日期),然后根据该标准 select,将它们基于过去或未来行的一系列标准复制并粘贴到另一个工作表中. 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.我的工作表按日期按 ASC 排序,并阅读了许多与此问题类似的帖子,但我没有自己解决,所以不知道我的问题是缺乏处理日期的专业知识,还是我的所有线程read 的要求略有不同。

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;我需要 VBA 的帮助,以找到今天的日期 19/07/2011 并将其粘贴到“过去”工作表中

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 (ie 28 days before and after today's date) and copy/pasting rows based on that.一旦我解决了这个问题,我将添加逻辑到“现在是什么日期”标准(即今天日期之前和之后的 28 天)并基于此复制/粘贴行。 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 (ie the system date which hopefully is the same), you use the Date function.因此,要回答您的问题,使用 function 获取当前日期(即希望相同的系统日期),您使用Date function。

Now you process he list and compare each date with the system date;现在您处理他的列表并将每个日期与系统日期进行比较;

  • dates < sysdate are past日期 < sysdate 已过去
  • dates > sysdate are future日期 > sysdate 是未来
  • dates = sysdate are ignored日期 = sysdate 被忽略

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.如果表中的日期包含时间信息,则必须使用Int(yourtabledate)来摆脱时间,因为02.08.2011 08:12 > 02.08.2011 (隐含时间00:00 ),因此 go 到未来你不想要。

For ther rest... if you don't know how to fomulate a loop across a table in VBA, post a specific question.对于 rest...

Cheers Mike干杯迈克

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM