View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett[_4_] Don Guillett[_4_] is offline
external usenet poster
 
Posts: 2,337
Default Fill column with dates of month depending on month in A1

Or for d7 down instead of d2

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address < "$D$1" Then Exit Sub
Range("d7:d" & Range("d7").End(xlDown).Row).ClearContents
Range("d7") = Range("d1") + 1
Set myrng = Range("d8:d40")
myrng.Formula = "=IF(d7="""","""",IF(MONTH(d7)=MONTH(d7+1),d7+1,"" ""))"
myrng.Value = myrng.Value
End Sub

--
Don Guillett
SalesAid Software

"Don Guillett" wrote in message
...
try testing this and then change to suit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address < "$D$1" Then Exit Sub
x = Day(DateSerial(Year([d1]), Month([d1]) + 1, 1) - 1) - Day([d1]) + 1
Range("d2:d" & Range("d2").End(xlDown).Row).ClearContents
Set myrng = Range("d2:d" & x)
myrng.Formula = "=d1+1"
myrng.Value = myrng.Value
End Sub

--
Don Guillett
SalesAid Software

wrote in message
oups.com...
I'm trying to figure out the following. A1 contains first of month and
is formated as Mmmm yyyy, A6 is =A1 and A7=A6+1 and so on formated as
mm/dd/yyyy. I want to programatically fill column A with the rest of
the days of the month when the user changes A1. I'm using Private Sub
Worksheet_change(ByVal Target As Range) to clear the old days and then
copy A7 down for the remainder of month. Can't figure out how to make
it stop at the end of the month. Thanks in advance for any help.