LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
Roy Roy is offline
external usenet poster
 
Posts: 53
Default Filling Column with date

Great observation. It made it fairly easy to diagnose. The only way to get 93
days is with a leap year malfunction. Note that the variable x is unaffected
by the Cases in the Select Case(Month(Range("A5")) section in all of the 92
day months. But since x was never initialized, it inherited zero by default.
If we initialize it to anything else, we avoid the problem and the Case
statements will change x as needed. See the one line addition below. That
should do the trick. It's 1:40 am, so I'll let you test it and let me know.

Roy

"Bill" wrote:

This works great with one exception if I put in a month where days equal 92
it gives me 93 days across the sheet. Can you help resolve this.

Thanks Bill

"Roy" wrote:

Bill,

Add a command button on your sheet and paste this code into the click
event. It checks for a valid date format, clears the old B5:CO6 area,
accounts for leap year and notes the days in a single letter configuration.
Give it a shot.

Roy

Dim StartMonth, Dayz, x As Integer
If IsDate(Range("A5")) = True Then
Range("B5:CO6").Select
Range("B5:CO6").ClearContents
Range("A5").Activate
StartMonth = Month(Range("A5"))
Select Case StartMonth
Case Is = 1, 12
Dayz = 90
Case Is = 2
Dayz = 89
Case Is = 3, 5, 6, 7, 8, 10, 11
Dayz = 92
Case Is = 4, 9
Dayz = 91
End Select


x = 5 'we don't care what it is as long as it's not zero! OOPS!

Select Case Month(Range("A5"))
Case Is = 12
x = (Year(Range("A5")) + 1) Mod 4
Case Is = 1, 2
x = Year(Range("A5")) Mod 4
End Select
If x = 0 Then Dayz = Dayz + 1
End If
Application.ScreenUpdating = False
For x = 1 To Dayz
Cells(5, x + 1).Value = Day(Range("A5") + x - 1)
Cells(5, x + 1).NumberFormat = "#"
Cells(6, x + 1).Value = Weekday(Range("A5") + x - 1)
Select Case Cells(6, x + 1).Value
Case Is = 1, 7
Cells(6, x + 1).Value = "S"
Case Is = 2
Cells(6, x + 1).Value = "M"
Case Is = 3, 5
Cells(6, x + 1).Value = "T"
Case Is = 4
Cells(6, x + 1).Value = "W"
Case Is = 6
Cells(6, x + 1).Value = "F"
End Select
Cells(6, x + 1).Value = Left(Cells(6, x + 1).Value, 1)
Next
Application.ScreenUpdating = True


"Bill" wrote:

I need some help. I have a spredsheet that displays three months of dates.

I place the start date in cell A5 like 1 Dec 04. Then starting in cloumn B5,
the Date is place in the cell. In cell B6, the day is insert.

EXAMPLE

A5 = 1 Dec 04 then
B5 = 1, and B6 = W for Wednesday
C5 = 2, and C6 = T for Thursday
D5 = 3, and D6 = F for Friday

this sequence would need to continue until the through the third month. As
in the case of this example it would need to continue through 28 Feb 05. Can
anyone please provide me the VBA code to accomplishs this tasks.

Thanks

Bill

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
filling a column Mary M. New Users to Excel 6 August 19th 09 06:52 PM
how to change column references, while filling down another column bclancy12 Excel Discussion (Misc queries) 1 June 7th 06 04:13 PM
Pre-filling column wnfisba Excel Discussion (Misc queries) 1 September 1st 05 10:35 PM
filling a two column listbox from a two column recordset Dennis Excel Programming 5 May 23rd 04 10:13 PM
Filling Column with Numbers Don Guillett[_4_] Excel Programming 0 August 31st 03 05:43 PM


All times are GMT +1. The time now is 04:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"