PC Review


Reply
Thread Tools Rate Thread

Autofill dates when 1 is entered in a cell

 
 
Jock
Guest
Posts: n/a
 
      19th Feb 2009
If a 1 is entered in any of C7 - C13, I would like to autofill sequential
numbers down column C up as far as the number 31. It's for a monthly sheet
with days of the week in column B. So regardless of which day is the 1st, the
code will copy the numbers down for the user.

Thanks,
--
Traa Dy Liooar

Jock
 
Reply With Quote
 
 
 
 
Bernie Deitrick
Guest
Posts: n/a
 
      19th Feb 2009
Jock,

Copy the code below into the codemodule of the ThisWorkbook object.

If you didn't understand that line, then follow the advice from David McRitchie:
"Unlike standard macros which are installed in standard modules, Workbook Events are installed in
ThisWorkBook in the following manner: F11 (Visual Basic Editor), Get into your project library
(name of your workbook) with Ctrl+R (View, Project Explorer), under the name of your workbook you
see Microsoft Excel Objects, then before Modules you see ThisWorkBook, doubleclick and paste the
code into the code window (F7)."


HTH,
Bernie
MS Excel MVP


Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Intersect(Target, Sh.Range("C7:C13")) Is Nothing Then Exit Sub
If Target.Cells.Count > 1 Then Exit Sub
If Target.Value <> 1 Then Exit Sub
Application.EnableEvents = False
Target.AutoFill Destination:=Target.Resize( _
Day(DateSerial(Year(Now), Month(Now) + 1, 0)), 1), _
Type:=xlFillSeries
Application.EnableEvents = True
End Sub


"Jock" <(E-Mail Removed)> wrote in message
news:412FE6C3-E895-403B-A23A-(E-Mail Removed)...
> If a 1 is entered in any of C7 - C13, I would like to autofill sequential
> numbers down column C up as far as the number 31. It's for a monthly sheet
> with days of the week in column B. So regardless of which day is the 1st, the
> code will copy the numbers down for the user.
>
> Thanks,
> --
> Traa Dy Liooar
>
> Jock



 
Reply With Quote
 
Jock
Guest
Posts: n/a
 
      20th Feb 2009
Great Bernie, thanks. Works better than expected.

Should a user enter the '1' in the wrong cell then proceed to enter it in
the correct cell, can your code be 'tweaked' to clear down column C7:C43
before autofilling from the new '1' thus removing numbers which would
otherwise be outside the autofill range and would not be overwritten?
--
Traa Dy Liooar

Jock


"Bernie Deitrick" wrote:

> Jock,
>
> Copy the code below into the codemodule of the ThisWorkbook object.
>
> If you didn't understand that line, then follow the advice from David McRitchie:
> "Unlike standard macros which are installed in standard modules, Workbook Events are installed in
> ThisWorkBook in the following manner: F11 (Visual Basic Editor), Get into your project library
> (name of your workbook) with Ctrl+R (View, Project Explorer), under the name of your workbook you
> see Microsoft Excel Objects, then before Modules you see ThisWorkBook, doubleclick and paste the
> code into the code window (F7)."
>
>
> HTH,
> Bernie
> MS Excel MVP
>
>
> Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
> If Intersect(Target, Sh.Range("C7:C13")) Is Nothing Then Exit Sub
> If Target.Cells.Count > 1 Then Exit Sub
> If Target.Value <> 1 Then Exit Sub
> Application.EnableEvents = False
> Target.AutoFill Destination:=Target.Resize( _
> Day(DateSerial(Year(Now), Month(Now) + 1, 0)), 1), _
> Type:=xlFillSeries
> Application.EnableEvents = True
> End Sub
>
>
> "Jock" <(E-Mail Removed)> wrote in message
> news:412FE6C3-E895-403B-A23A-(E-Mail Removed)...
> > If a 1 is entered in any of C7 - C13, I would like to autofill sequential
> > numbers down column C up as far as the number 31. It's for a monthly sheet
> > with days of the week in column B. So regardless of which day is the 1st, the
> > code will copy the numbers down for the user.
> >
> > Thanks,
> > --
> > Traa Dy Liooar
> >
> > Jock

>
>
>

 
Reply With Quote
 
Bernie Deitrick
Guest
Posts: n/a
 
      20th Feb 2009
Jock,

Try this version...

HTH,
Bernie
MS Excel MVP


Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Intersect(Target, Sh.Range("C7:C13")) Is Nothing Then Exit Sub
If Target.Cells.Count > 1 Then Exit Sub
If Target.Value <> 1 Then Exit Sub
Application.EnableEvents = False
'Clear old stuff below
Target.Offset(1).Resize(43 - Target.Row).ClearContents
'Clear old stuff above
If Target.Row <> 7 Then
Target.Offset(7 - Target.Row).Resize(Target.Row - 7).ClearContents
End If
Target.AutoFill Destination:=Target.Resize( _
Day(DateSerial(Year(Now), Month(Now) + 1, 0)), 1), _
Type:=xlFillSeries
Application.EnableEvents = True
End Sub


"Jock" <(E-Mail Removed)> wrote in message
news:51C336C2-3A57-47F1-AF14-(E-Mail Removed)...
> Great Bernie, thanks. Works better than expected.
>
> Should a user enter the '1' in the wrong cell then proceed to enter it in
> the correct cell, can your code be 'tweaked' to clear down column C7:C43
> before autofilling from the new '1' thus removing numbers which would
> otherwise be outside the autofill range and would not be overwritten?
> --
> Traa Dy Liooar
>
> Jock
>
>
> "Bernie Deitrick" wrote:
>
>> Jock,
>>
>> Copy the code below into the codemodule of the ThisWorkbook object.
>>
>> If you didn't understand that line, then follow the advice from David McRitchie:
>> "Unlike standard macros which are installed in standard modules, Workbook Events are installed in
>> ThisWorkBook in the following manner: F11 (Visual Basic Editor), Get into your project library
>> (name of your workbook) with Ctrl+R (View, Project Explorer), under the name of your workbook you
>> see Microsoft Excel Objects, then before Modules you see ThisWorkBook, doubleclick and paste the
>> code into the code window (F7)."
>>
>>
>> HTH,
>> Bernie
>> MS Excel MVP
>>
>>
>> Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
>> If Intersect(Target, Sh.Range("C7:C13")) Is Nothing Then Exit Sub
>> If Target.Cells.Count > 1 Then Exit Sub
>> If Target.Value <> 1 Then Exit Sub
>> Application.EnableEvents = False
>> Target.AutoFill Destination:=Target.Resize( _
>> Day(DateSerial(Year(Now), Month(Now) + 1, 0)), 1), _
>> Type:=xlFillSeries
>> Application.EnableEvents = True
>> End Sub
>>
>>
>> "Jock" <(E-Mail Removed)> wrote in message
>> news:412FE6C3-E895-403B-A23A-(E-Mail Removed)...
>> > If a 1 is entered in any of C7 - C13, I would like to autofill sequential
>> > numbers down column C up as far as the number 31. It's for a monthly sheet
>> > with days of the week in column B. So regardless of which day is the 1st, the
>> > code will copy the numbers down for the user.
>> >
>> > Thanks,
>> > --
>> > Traa Dy Liooar
>> >
>> > Jock

>>
>>
>>



 
Reply With Quote
 
Jock
Guest
Posts: n/a
 
      23rd Feb 2009
Fantastic Bernie, thanks!
--
Traa Dy Liooar

Jock


"Bernie Deitrick" wrote:

> Jock,
>
> Try this version...
>
> HTH,
> Bernie
> MS Excel MVP
>
>
> Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
> If Intersect(Target, Sh.Range("C7:C13")) Is Nothing Then Exit Sub
> If Target.Cells.Count > 1 Then Exit Sub
> If Target.Value <> 1 Then Exit Sub
> Application.EnableEvents = False
> 'Clear old stuff below
> Target.Offset(1).Resize(43 - Target.Row).ClearContents
> 'Clear old stuff above
> If Target.Row <> 7 Then
> Target.Offset(7 - Target.Row).Resize(Target.Row - 7).ClearContents
> End If
> Target.AutoFill Destination:=Target.Resize( _
> Day(DateSerial(Year(Now), Month(Now) + 1, 0)), 1), _
> Type:=xlFillSeries
> Application.EnableEvents = True
> End Sub
>
>
> "Jock" <(E-Mail Removed)> wrote in message
> news:51C336C2-3A57-47F1-AF14-(E-Mail Removed)...
> > Great Bernie, thanks. Works better than expected.
> >
> > Should a user enter the '1' in the wrong cell then proceed to enter it in
> > the correct cell, can your code be 'tweaked' to clear down column C7:C43
> > before autofilling from the new '1' thus removing numbers which would
> > otherwise be outside the autofill range and would not be overwritten?
> > --
> > Traa Dy Liooar
> >
> > Jock
> >
> >
> > "Bernie Deitrick" wrote:
> >
> >> Jock,
> >>
> >> Copy the code below into the codemodule of the ThisWorkbook object.
> >>
> >> If you didn't understand that line, then follow the advice from David McRitchie:
> >> "Unlike standard macros which are installed in standard modules, Workbook Events are installed in
> >> ThisWorkBook in the following manner: F11 (Visual Basic Editor), Get into your project library
> >> (name of your workbook) with Ctrl+R (View, Project Explorer), under the name of your workbook you
> >> see Microsoft Excel Objects, then before Modules you see ThisWorkBook, doubleclick and paste the
> >> code into the code window (F7)."
> >>
> >>
> >> HTH,
> >> Bernie
> >> MS Excel MVP
> >>
> >>
> >> Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
> >> If Intersect(Target, Sh.Range("C7:C13")) Is Nothing Then Exit Sub
> >> If Target.Cells.Count > 1 Then Exit Sub
> >> If Target.Value <> 1 Then Exit Sub
> >> Application.EnableEvents = False
> >> Target.AutoFill Destination:=Target.Resize( _
> >> Day(DateSerial(Year(Now), Month(Now) + 1, 0)), 1), _
> >> Type:=xlFillSeries
> >> Application.EnableEvents = True
> >> End Sub
> >>
> >>
> >> "Jock" <(E-Mail Removed)> wrote in message
> >> news:412FE6C3-E895-403B-A23A-(E-Mail Removed)...
> >> > If a 1 is entered in any of C7 - C13, I would like to autofill sequential
> >> > numbers down column C up as far as the number 31. It's for a monthly sheet
> >> > with days of the week in column B. So regardless of which day is the 1st, the
> >> > code will copy the numbers down for the user.
> >> >
> >> > Thanks,
> >> > --
> >> > Traa Dy Liooar
> >> >
> >> > Jock
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
autofill colour based on date entered Tacrier Microsoft Excel Misc 4 17th Dec 2008 06:02 PM
How can I autofill dates having a blank cell between each day? Dee Microsoft Excel New Users 1 3rd Jul 2008 04:59 AM
Can related Access form fields autofill after 1 field is entered? =?Utf-8?B?UmFjaGVsc0ZydXN0cmF0aW9u?= Microsoft Access Getting Started 2 15th Nov 2005 07:49 PM
If both dates are entered into a cell then answer is yes =?Utf-8?B?VGVyZXNhIFdhcm5l?= Microsoft Excel Worksheet Functions 2 30th Oct 2004 02:56 PM
Autofill City and County info based on Zip Code entered Tim Atkins Microsoft Access Forms 2 16th Jul 2004 03:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:10 AM.