VBA Express Forum  




Go Back   VBA Express Forum > VBA Code & Other Help > Excel Help
     Feedback     
Register FAQ Members Arcade Knowledge Base Training Articles Consulting

Reply
 
Thread Tools Display Modes
Old 11-04-2010, 10:28 AM   #1
gregpio

 
Joined: Nov 2010
Posts: 2
Kb Entries: 0
Articles: 0
Solved: Set a variable as todays date minus X days.

Hi,
My apologies beforehand if my problem is remedial or if any of my terminology is off. I've been using excel for close to ten years, but have just begun to explore VBA and I have a limited understanding of programming languages in general so the whole theory of programming is a bit hazy.
This forum has provided a great deal of help to me so far in getting established with vba so thank you to everyone who contributes here, but I now face a problem that I can not find a solution to by scouring the web.

I have a spreadsheet that contains all overdue invoices. Each record shows the invoice number, the customer it belongs to, due date, amount, etc.

What I'd like to have VBA do is read every due date and copy to separate sheets the invoices that are due today, 30 days overdue, and 60 days overdue.

My idea was to set a variable equal todays date for due today, todays date minus 30 days for thirty days overdue, and todays date minus 60 days for 60 days overdue. Something like:
VBA:
Dim DueToday Set DueToday = Date Dim DueThirty Set DueThirty = Date - 30 Dim DueSixty Set DueSixty = Date - 60
VBA tags courtesy of www.thecodenet.com
Then scan the "Due Date" column for matches abd copy and paste the entire matched row to a certain sheet depending on how overdue the invoice is.

I have tried usinig a few examples from other posts but no ones examples matched and I am unable to fit the solution to my problem. Any input on how to set the variables correctly or scan the Due Date column would be awesome.

Cheers!

Local Time: 05:20 AM
Local Date: 05-26-2013
Location:

 
Reply With Quote Top
Old 11-04-2010, 10:59 AM   #2
xld
 
xld's Avatar
Distinguished Lord of VBAX

 
Joined: Apr 2005
Posts: 23,118
Kb Entries: 3
Articles: 2
VBA:
With Activesheet Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row For i = 1 To LastRow If .Cells(i, "A").Value < Date - 60 Then Row60 = Row60+1 .Cells(i, "A").Copy Worksheets("Sheet2").Cells(Row60,"A") ElseIf .Cells(i, "A").Value < Date - 30 Then Row30 = Row30+1 .Cells(i, "A").Copy Worksheets("Sheet2").Cells(Row30,"A") ElseIf .Cells(i, "A").Value < Date Then Row0 = Row0+1 .Cells(i, "A").Copy Worksheets("Sheet2").Cells(Row0,"A") End If Next i End With
VBA tags courtesy of www.thecodenet.com


____________________________________________
Nihil simul inventum est et perfectum

Abusus non tollit usum

Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber

Local Time: 10:20 AM
Local Date: 05-26-2013
Location:

 
Reply With Quote Top
Old 11-04-2010, 12:09 PM   #3
gregpio

 
Joined: Nov 2010
Posts: 2
Kb Entries: 0
Articles: 0
Thanks XLD, that worked incredibly well and is much fast than the rest of my macro.
I don't care what everyone says about chileans, you guys are alright.
jk... If you ever need anything just pm me and I'd be happy to help.

Local Time: 05:20 AM
Local Date: 05-26-2013
Location:

 
Reply With Quote Top
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -7. The time now is 02:20 AM.


Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright © 2004 - 2012 VBA Express