Macro to Autofill Dates between Start Date and End Date

lewis1

Board Regular
Joined
Jul 20, 2009
Messages
81
Hi, I have looked around the net, but I can't find a clear answer for the following.

I have a Start Date, eg: 08/23/2013 in Cell "D5", and
End Date; eg: 08/22/2018 in Cell "D7"

I would like a Macro which starts in Cell "D12" autofills column "D" with all the dates between and including the start and end date.

The name of the sheet I would like the macro to run on is named "Calendar"

Thanks!
Lewis.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Code:
Sub FillCal()
    Dim StartD as Date, EndD as Date
    StartD=Calandar.Cells(5,4)
    EndD=Calandar.Cells(7,4)
    For row= 1 to endD - startd
        cells(row,4)=startD+row-1
    Next row
End sub
 
Upvote 0
Hey, this is the error I get now.

"Compile error:
Invalid qualifier"

With StartD = Calendar.Cells(5, 4)

-Calendar highlighted.

Any help would be appreciated.

Thanks
 
Upvote 0
check the spelling of your sheet name.
 
Upvote 0
Fixed, thanks very much the code is working.

I removed the sheet reference and simply defined the ranges and that works.

Thanks again.
 
Upvote 0
Hi,

I posted these additional questions in another thread, but I was directed to bring them back here.

I would like to expand the Macro to perform the following:

1. Point out the THIRD 'wednesday' of every month with a "1" in column D.
2. Point out the second last 'weekday' of every month with a "1"in column E.

Is this something anyone can help with, realize it might be too much

Also, for the first solution, if I want the macro to start in Range("C10") what adjustment should I make,.

Thanks!
Lewis.
 
Upvote 0
post your code so we can modify what you have and no more typos from my end
 
Upvote 0
This is what I am starting with..

Actually with the below, I am only returning 11 results for

Start Date8/23/2013
Days 20.00
End Date 9/12/2013

<colgroup><col><col></colgroup><tbody>
</tbody>

Code:
Sub FillCal()
    Dim StartD As Date, EndD As Date
    
    StartD = Range("D5")
    EndD = Range("D7")
    
    For Row = 10 To EndD - StartD
        Cells(Row, 4) = StartD + Row - 1
    Next Row
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,207
Members
448,554
Latest member
Gleisner2

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