VBA - dragging down date

Fredek

Board Regular
Joined
Mar 8, 2011
Messages
65
Hi guys,

I need a bit of help writing a code that will effectively drag the last date in column B up to yesterday's date.

The first date in cell B2 is 02/04/2012. I could either start at 02/04/2012 and drag it down by the number of days so something like 'yesterday's date minus 02/04/2012. Or find the last date in column B and drag it down to yesterday's date, again doing some subtraction to find the number of dates to add.

Any help would be very much appreciated.

Many thanks,
Fred
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
In B2, Enter
Code:
=DATE(2012,4,ROW())

Then drag down until the desired date is reached
 
Last edited:
Upvote 0
Or find the last date in column B and drag it down to yesterday's date, again doing some subtraction to find the number of dates to add.

One option for this might be..

Code:
With Range("B" & Rows.Count).End(xlUp)
    .AutoFill .Resize(Date - .Value), xlFillSeries
End With
 
Upvote 0
FormR, when I run the code twice in a day I get a Run Time Error '1004'.

Is there an efficient way to get past this? Basically so that nothing happens if the yesterday's date has already been added to the spreadsheet?
 
Upvote 0
Hi, you could try like this:

Code:
With Range("B" & Rows.Count).End(xlUp)
    If .Value < Date - 1 Then .AutoFill .Resize(Date - .Value), xlFillSeries
End With
 
Upvote 0

Forum statistics

Threads
1,223,953
Messages
6,175,598
Members
452,658
Latest member
GStorm

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