Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default To populate a column with a date

Hi there folks,
I need a macro (a formula wont cut it) that writes dates in the format
of "50925" (this being the 25th September 2005). I also need to append
a "-1" or a "-2" such that the first three days will appear as follows:
50925-1
50925-2
50926-1
50926-2
50927-1
50927-2
I also need write these dates for a whole year.
The idea is to have a user select one of the two "High Tides"
for any day of the year from a lookup table.

When this is done a graphical representation will be produced using the
parameters drawn from the lookup.

Hope someone can help

and Many thanks in advance.

Geoff

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default To populate a column with a date

Here is a solution -- needs refinement but it works!


Sub DateBuild()
Dim syear As Long, smonth As Integer, sday As Integer
Dim eyear As Long, emonth As Integer, eday As Integer

' set start of period
syear = 2005
smonth = 1
sday = 1
' set end period date
eyear = 2005
emonth = 12
eday = 31


Dim sDate As Date, eDate As Date
sDate = DateSerial(syear, smonth, sday)
eDate = DateSerial(eyear, emonth, eday)

Dim x As Date, xr As Long, xstep As Integer
Dim smn As String, sdy As String
xr = 1
For x = sDate To eDate
xstep = 1
For xstep = 1 To 2

smn = Month(x)
If Month(x) < 10 Then smn = "0" & CStr(Month(x))
sdy = Day(x)
If Day(x) < 10 Then sdy = "0" & CStr(Day(x))

Cells(xr, 1) = CStr(Year(x) - 2000) & smn & sdy & "-" & CStr(xstep)

xr = xr + 1
Next xstep
xstep = xstep + 1
Next
End Sub

--
Cheers
Nigel



wrote in message
oups.com...
Hi there folks,
I need a macro (a formula wont cut it) that writes dates in the format
of "50925" (this being the 25th September 2005). I also need to append
a "-1" or a "-2" such that the first three days will appear as follows:
50925-1
50925-2
50926-1
50926-2
50927-1
50927-2
I also need write these dates for a whole year.
The idea is to have a user select one of the two "High Tides"
for any day of the year from a lookup table.

When this is done a graphical representation will be produced using the
parameters drawn from the lookup.

Hope someone can help

and Many thanks in advance.

Geoff



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default To populate a column with a date

Thank you Nigel....

That works perfectly. Even takes care of the varying numbers of days in
a month. Probably even a leapyear as well.

Also learnt a heap about VBA.

Geoff

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default To populate a column with a date

Hi Geoff,

a bit shorter:
For the year 2005

Sub test()
Dim lngD As Long
Dim i As Integer
range("a1").Select
For lngD = 38353 To 38353 + 364
For i = 1 To 2
ActiveCell.Value = Right(Format(lngD, "yymmdd") & "-" & i, 7)
ActiveCell.Offset(1, 0).Select
Next
Next
End Sub

For other periods please change the numbers in
"For lngD = 38353 To 38353 + 364")

e.g first half 2006 it would be
"For lngD = 38717 To 38717 + 182")

Wolf

" wrote:

Thank you Nigel....

That works perfectly. Even takes care of the varying numbers of days in
a month. Probably even a leapyear as well.

Also learnt a heap about VBA.

Geoff


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default To populate a column with a date

Wolf.

Thankyou for that very eloquent piece of code. It also worked
perfectly.
Just loved the way you stripped that leading zero off.

Regards
Geoff

Reply
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
Function to lookup date on tab in excel and populate date on calen MGC Excel Worksheet Functions 0 February 4th 10 04:48 AM
Populate days of the month in a column by checking on date Joe Excel Worksheet Functions 4 March 5th 09 05:56 AM
Earliest Date to populate? sonquizzon Excel Worksheet Functions 2 June 16th 05 07:35 PM
Populate a column by extracting unique values from another column? Mike Palmer Excel Worksheet Functions 2 June 10th 05 03:21 PM
total populate date JBP Excel Programming 2 February 17th 04 06:57 PM


All times are GMT +1. The time now is 09:17 AM.

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"