Date within a year from now

tomleitch

Board Regular
Joined
Jan 3, 2012
Messages
189
Hi all,

I've had a search but I can't really find what I'm trying to do.....

I'm running through cells and I want to only use cells that have a date within the next year


The code I have is this:

Code:
With CreateObject("scripting.dictionary") 


      For Each cl In Ws2.Range("A10", Ws2.Range("A" & Rows.Count).End(xlUp))
      If Cells(cl.Row, PLANWST).Value < (Date + 365) And Not .exists(cl.Value) Then .Add cl.Value, Array(cl.Offset(, 1).Value, cl.Offset(, 3).Value, cl.Offset(, 4).Value, cl.Offset(, 5).Value, cl.Offset(, 6).Value, cl.Offset(, 7).Value, cl.Offset(, 8).Value, cl.Offset(, 9).Value, cl.Offset(, 10).Value)
      Next cl

(PLANWST is the column reference of my date column)

The code doesn't seem to work and I think it's this bit that's wrong:

Code:
If Cells(cl.Row, PLANWST).Value < (Date + 365)


Any help appreciated

Thanks
Tom
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Hi all,

I've had a search but I can't really find what I'm trying to do.....

I'm running through cells and I want to only use cells that have a date within the next year


The code I have is this:

Code:
With CreateObject("scripting.dictionary") 


      For Each cl In Ws2.Range("A10", Ws2.Range("A" & Rows.Count).End(xlUp))
      If Cells(cl.Row, PLANWST).Value < (Date + 365) And Not .exists(cl.Value) Then .Add cl.Value, Array(cl.Offset(, 1).Value, cl.Offset(, 3).Value, cl.Offset(, 4).Value, cl.Offset(, 5).Value, cl.Offset(, 6).Value, cl.Offset(, 7).Value, cl.Offset(, 8).Value, cl.Offset(, 9).Value, cl.Offset(, 10).Value)
      Next cl

(PLANWST is the column reference of my date column)

The code doesn't seem to work and I think it's this bit that's wrong:

Code:
If Cells(cl.Row, PLANWST).Value < (Date + 365)


Any help appreciated

Thanks
Tom
https://docs.microsoft.com/en-us/office/vba/Language/Reference/User-Interface-Help/dictionary-object
 
Upvote 0

Thanks for the pointer MoshiM, but I'm still not sure exactly where I'm going wrong... I had a look at the article but I'm still not any the wiser.

I'm trying to tell it that if the date is more than a year in the future then not to include the item in the dictionary.

The rest of it is working fine, if I just take the bit out thats trying to check the date - so I know that the rest of my code is ok.

Thanks
Tom
 
Upvote 0
Thanks for the pointer MoshiM, but I'm still not sure exactly where I'm going wrong... I had a look at the article but I'm still not any the wiser.

I'm trying to tell it that if the date is more than a year in the future then not to include the item in the dictionary.

The rest of it is working fine, if I just take the bit out thats trying to check the date - so I know that the rest of my code is ok.

Thanks
Tom
Try
Code:
Dim D as dictionary
Set D=CreateObject("scripting.dictionary")


With D


      For Each cl In Ws2.Range("A10", Ws2.Range("A" & Rows.Count).End(xlUp))
      If Cells(cl.Row, PLANWST).Value < (Date + 365) And Not .exists(cl.Value) Then .Add cl.Value, Array(cl.Offset(, 1).Value, cl.Offset(, 3).Value, cl.Offset(, 4).Value, cl.Offset(, 5).Value, cl.Offset(, 6).Value, cl.Offset(, 7).Value, cl.Offset(, 8).Value, cl.Offset(, 9).Value, cl.Offset(, 10).Value) [COLOR=#333333]     
 Next cl[/COLOR]
 
Upvote 0
Try
Code:
Dim D as dictionary
Set D=CreateObject("scripting.dictionary")


With D


      For Each cl In Ws2.Range("A10", Ws2.Range("A" & Rows.Count).End(xlUp))
      If Cells(cl.Row, PLANWST).Value < (Date + 365) And Not .exists(cl.Value) Then .Add cl.Value, Array(cl.Offset(, 1).Value, cl.Offset(, 3).Value, cl.Offset(, 4).Value, cl.Offset(, 5).Value, cl.Offset(, 6).Value, cl.Offset(, 7).Value, cl.Offset(, 8).Value, cl.Offset(, 9).Value, cl.Offset(, 10).Value) [COLOR=#333333]     
 Next cl[/COLOR]

All sorted now - thanks :)
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,301
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top