Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Toggle a range of Julian dates to Gregorian Dates and Back

Hello All!
*Excel 2003*

I have a 2 bits of code I coppied from Chip Pearsons Website that changes my
Julian dates to Gregorian dates and back again.

I have a Worksheet that I would like to use this code on but I would like it
to look at 2 columns ("D" and "I") that contain Julian dates ie.(04354)
formatted as text and run this function on the entire Used Range of both
columns (minus the Header row). As the functions loop through the ranges I
want to replace the old Julian values with the new Gregorian values. I will
then run some proceedures that include the Gregorian Dates and after I am
finished I wish to return them to their previous Julian Dates.

Basiclly I want the ability to toggle these date formats back and forth from
within other proceedures. Can anyone assist me with this code? My julian
date functions are posted below.

Function JDateToGDate1(JDate As String) As Long
Dim TheYear As Integer
Dim TheDay As Integer
Dim GDate As Long

TheYear = CInt(Left(JDate, 2))
If TheYear < 30 Then
TheYear = TheYear + 2000
Else
TheYear = TheYear + 1900
End If

TheDay = CInt(Right(JDate, 3))
GDate = DateSerial(TheYear, 1, TheDay)
JDateToGDate1 = GDate

End Function

'************** And**************

Function GDateToJDate1(GDate As Long) As String
Dim TheYear As Integer
Dim TheDays As Integer
Dim JDate As String

TheYear = Year(GDate)
TheDays = DateDiff("d", DateSerial(TheYear, 1, 0), GDate)
JDate = Right(Format(TheYear, "0000"), 2) & Format(TheDays, "000")
GDateToJDate1 = JDate

End Function


Thanks in advance for your assistance,
--

Patrick
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default Toggle a range of Julian dates to Gregorian Dates and Back

PS

This will convert TO Julian. Make an identical sub and change the function
to convert FROM Julian

Sub ToggleJ()

Dim rCell As Range
Dim rRange As Range

With ActiveSheet
Set rRange = Intersect(.UsedRange, Union(.Columns("D"),
..Columns("I")))
Set rRange = rRange.Offset(1).Resize(rRange.Rows.Count - 1)
End With

For Each rCell In rRange.Cells
rCell.Value = GDateToJDate1(rCell.Value)
Next rCell

End Sub

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com

PSKelligan wrote:
Hello All!
*Excel 2003*

I have a 2 bits of code I coppied from Chip Pearsons Website that
changes my Julian dates to Gregorian dates and back again.

I have a Worksheet that I would like to use this code on but I would
like it to look at 2 columns ("D" and "I") that contain Julian dates
ie.(04354) formatted as text and run this function on the entire Used
Range of both columns (minus the Header row). As the functions loop
through the ranges I want to replace the old Julian values with the
new Gregorian values. I will then run some proceedures that include
the Gregorian Dates and after I am finished I wish to return them to
their previous Julian Dates.

Basiclly I want the ability to toggle these date formats back and
forth from within other proceedures. Can anyone assist me with this
code? My julian date functions are posted below.

Function JDateToGDate1(JDate As String) As Long
Dim TheYear As Integer
Dim TheDay As Integer
Dim GDate As Long

TheYear = CInt(Left(JDate, 2))
If TheYear < 30 Then
TheYear = TheYear + 2000
Else
TheYear = TheYear + 1900
End If

TheDay = CInt(Right(JDate, 3))
GDate = DateSerial(TheYear, 1, TheDay)
JDateToGDate1 = GDate

End Function

'************** And**************

Function GDateToJDate1(GDate As Long) As String
Dim TheYear As Integer
Dim TheDays As Integer
Dim JDate As String

TheYear = Year(GDate)
TheDays = DateDiff("d", DateSerial(TheYear, 1, 0), GDate)
JDate = Right(Format(TheYear, "0000"), 2) & Format(TheDays, "000")
GDateToJDate1 = JDate

End Function


Thanks in advance for your assistance,



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default Toggle a range of Julian dates to Gregorian Dates and Back

PS

Scratch that. I guess Resize doesn't work well with Areas. Change to this

Sub ToggleJ()

Dim rCell As Range
Dim rRange As Range

With ActiveSheet
Set rRange = Intersect(.UsedRange, Union(.Columns("D"),
..Columns("I")))
Set rRange = rRange.Offset(1)
End With

For Each rCell In rRange.Cells
If Not IsEmpty(rCell.Value) Then
rCell.Value = GDateToJDate1(rCell.Value)
End If
Next rCell

End Sub

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com

Dick Kusleika wrote:
PS

This will convert TO Julian. Make an identical sub and change the
function to convert FROM Julian

Sub ToggleJ()

Dim rCell As Range
Dim rRange As Range

With ActiveSheet
Set rRange = Intersect(.UsedRange, Union(.Columns("D"),
.Columns("I")))
Set rRange = rRange.Offset(1).Resize(rRange.Rows.Count - 1)
End With

For Each rCell In rRange.Cells
rCell.Value = GDateToJDate1(rCell.Value)
Next rCell

End Sub


PSKelligan wrote:
Hello All!
*Excel 2003*

I have a 2 bits of code I coppied from Chip Pearsons Website that
changes my Julian dates to Gregorian dates and back again.

I have a Worksheet that I would like to use this code on but I would
like it to look at 2 columns ("D" and "I") that contain Julian dates
ie.(04354) formatted as text and run this function on the entire Used
Range of both columns (minus the Header row). As the functions loop
through the ranges I want to replace the old Julian values with the
new Gregorian values. I will then run some proceedures that include
the Gregorian Dates and after I am finished I wish to return them to
their previous Julian Dates.

Basiclly I want the ability to toggle these date formats back and
forth from within other proceedures. Can anyone assist me with this
code? My julian date functions are posted below.

Function JDateToGDate1(JDate As String) As Long
Dim TheYear As Integer
Dim TheDay As Integer
Dim GDate As Long

TheYear = CInt(Left(JDate, 2))
If TheYear < 30 Then
TheYear = TheYear + 2000
Else
TheYear = TheYear + 1900
End If

TheDay = CInt(Right(JDate, 3))
GDate = DateSerial(TheYear, 1, TheDay)
JDateToGDate1 = GDate

End Function

'************** And**************

Function GDateToJDate1(GDate As Long) As String
Dim TheYear As Integer
Dim TheDays As Integer
Dim JDate As String

TheYear = Year(GDate)
TheDays = DateDiff("d", DateSerial(TheYear, 1, 0), GDate)
JDate = Right(Format(TheYear, "0000"), 2) & Format(TheDays, "000")
GDateToJDate1 = JDate

End Function


Thanks in advance for your assistance,



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Toggle a range of Julian dates to Gregorian Dates and Back

Dick,

Works perfectly! Thanks for the assist.

V/R,
Patrick

"Dick Kusleika" wrote:

PS

Scratch that. I guess Resize doesn't work well with Areas. Change to this

Sub ToggleJ()

Dim rCell As Range
Dim rRange As Range

With ActiveSheet
Set rRange = Intersect(.UsedRange, Union(.Columns("D"),
..Columns("I")))
Set rRange = rRange.Offset(1)
End With

For Each rCell In rRange.Cells
If Not IsEmpty(rCell.Value) Then
rCell.Value = GDateToJDate1(rCell.Value)
End If
Next rCell

End Sub

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Toggle a range of Julian dates to Gregorian Dates and Back

Dear friend.
What do you think to put in GDate in
" Function GDateToJDate1(GDate As Long) As String" ?
because GDate is a long if you put exemple 12/04/2007 will be error.

Give a exemple.





"PSKelligan" wrote:

Hello All!
*Excel 2003*

I have a 2 bits of code I coppied from Chip Pearsons Website that changes my
Julian dates to Gregorian dates and back again.

I have a Worksheet that I would like to use this code on but I would like it
to look at 2 columns ("D" and "I") that contain Julian dates ie.(04354)
formatted as text and run this function on the entire Used Range of both
columns (minus the Header row). As the functions loop through the ranges I
want to replace the old Julian values with the new Gregorian values. I will
then run some proceedures that include the Gregorian Dates and after I am
finished I wish to return them to their previous Julian Dates.

Basiclly I want the ability to toggle these date formats back and forth from
within other proceedures. Can anyone assist me with this code? My julian
date functions are posted below.

Function JDateToGDate1(JDate As String) As Long
Dim TheYear As Integer
Dim TheDay As Integer
Dim GDate As Long

TheYear = CInt(Left(JDate, 2))
If TheYear < 30 Then
TheYear = TheYear + 2000
Else
TheYear = TheYear + 1900
End If

TheDay = CInt(Right(JDate, 3))
GDate = DateSerial(TheYear, 1, TheDay)
JDateToGDate1 = GDate

End Function

'************** And**************

Function GDateToJDate1(GDate As Long) As String
Dim TheYear As Integer
Dim TheDays As Integer
Dim JDate As String

TheYear = Year(GDate)
TheDays = DateDiff("d", DateSerial(TheYear, 1, 0), GDate)
JDate = Right(Format(TheYear, "0000"), 2) & Format(TheDays, "000")
GDateToJDate1 = JDate

End Function


Thanks in advance for your assistance,
--

Patrick

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
JULIAN DATES? DestinySky Excel Worksheet Functions 8 May 28th 08 05:18 PM
dates format using gregorian and hijri calendars sarif Excel Discussion (Misc queries) 0 December 12th 07 05:40 AM
Converting Julian Dates to regular dates CDTucson Excel Worksheet Functions 2 June 7th 07 04:20 AM
Julian dates nick Excel Discussion (Misc queries) 3 May 8th 06 04:48 PM
julian dates Lylesm Excel Discussion (Misc queries) 5 January 5th 06 07:45 PM


All times are GMT +1. The time now is 01:37 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"