Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default WS formula for Julian date not converting well to VBA??

I found the formula on Chip Pearson's site for converting a date to a Julian
date. When I try to use it as a VBA-inserted formula, it's not working out.
I keep getting an error message telling me "Expected: a close parenthesis
after the second YEAR". But doing that doesn't work. Can someone point me
to my error?

ws.Range("E1").Formula = "AR"& RIGHT(YEAR(Range("B1")),2)&
TEXT(Range("B1")-DATE(YEAR(Range("B1")),1,0),"000")

TIA
Ed


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default WS formula for Julian date not converting well to VBA??

post the formula you want in the cell.

--
Regards,
Tom Ogilvy

"Ed" wrote in message
...
I found the formula on Chip Pearson's site for converting a date to a

Julian
date. When I try to use it as a VBA-inserted formula, it's not working

out.
I keep getting an error message telling me "Expected: a close parenthesis
after the second YEAR". But doing that doesn't work. Can someone point

me
to my error?

ws.Range("E1").Formula = "AR"& RIGHT(YEAR(Range("B1")),2)&
TEXT(Range("B1")-DATE(YEAR(Range("B1")),1,0),"000")

TIA
Ed




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default WS formula for Julian date not converting well to VBA??

"Ed" wrote in message
...
: I found the formula on Chip Pearson's site for converting a date to a
Julian
: date. When I try to use it as a VBA-inserted formula, it's not working
out.
: I keep getting an error message telling me "Expected: a close parenthesis
: after the second YEAR". But doing that doesn't work. Can someone point
me
: to my error?
:
: ws.Range("E1").Formula = "AR"& RIGHT(YEAR(Range("B1")),2)&
: TEXT(Range("B1")-DATE(YEAR(Range("B1")),1,0),"000")
:
: TIA
: Ed
:

Ed,
Chips formula is meant to be pasted directly into a cell. To mimic this
from VBA you need to slightly modify

ws.Range("E1").Formula = "= ""AR"" & RIGHT(YEAR(B1),2) &
TEXT(B1-DATE(YEAR(B1),1,0),""000"")"

Note the double quotes and don't use range as this is VBA code and not
needed for a formula in a cell

Paul D


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default WS formula for Julian date not converting well to VBA??


"PaulD" <nospam wrote in message
...
: "Ed" wrote in message
: ...
: : I found the formula on Chip Pearson's site for converting a date to a
: Julian
: : date. When I try to use it as a VBA-inserted formula, it's not working
: out.
: <snip

: Ed,
: Chips formula is meant to be pasted directly into a cell. To mimic this
: from VBA you need to slightly modify
:
: ws.Range("E1").Formula = "= ""AR"" & RIGHT(YEAR(B1),2) &
: TEXT(B1-DATE(YEAR(B1),1,0),""000"")"

<snip

If you don't need the formula, just the result, you could also use

Public Function JulianDate(TheDate As Date)
JulianDate = Right(Year(TheDate), 2) & Format(DatePart("y", TheDate),
"000")
End Function
Then in cell E1, enter =JulianDate(B1)

Paul D


  #5   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default WS formula for Julian date not converting well to VBA??

Paul: Thanks for the help.

: Chips formula is meant to be pasted directly into a cell. To mimic this
: from VBA you need to slightly modify
:
: ws.Range("E1").Formula = "= ""AR"" & RIGHT(YEAR(B1),2) &
: TEXT(B1-DATE(YEAR(B1),1,0),""000"")"


Unfortunately, when I copy your version in, the VBE highlights TEXT and pops
up an error saying "Expected end of statement"??? (I did put it all on one
line.)

If you don't need the formula, just the result, you could also use


What I'm trying to do is use a date entered into a cell in mm/dd/yyyy format
to create a serialized number. Hence, it must be static, not dynamic - it
can't change every time I open the workbook on a new day. (That's also why
I add the "AR" to the beginning.)

Ed

"PaulD" <nospam wrote in message
...

"PaulD" <nospam wrote in message
...
: "Ed" wrote in message
: ...
: : I found the formula on Chip Pearson's site for converting a date to a
: Julian
: : date. When I try to use it as a VBA-inserted formula, it's not

working
: out.
: <snip

: Ed,
: Chips formula is meant to be pasted directly into a cell. To mimic this
: from VBA you need to slightly modify
:
: ws.Range("E1").Formula = "= ""AR"" & RIGHT(YEAR(B1),2) &
: TEXT(B1-DATE(YEAR(B1),1,0),""000"")"

<snip

If you don't need the formula, just the result, you could also use

Public Function JulianDate(TheDate As Date)
JulianDate = Right(Year(TheDate), 2) & Format(DatePart("y", TheDate),
"000")
End Function
Then in cell E1, enter =JulianDate(B1)

Paul D






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default WS formula for Julian date not converting well to VBA??

"Ed" wrote in message
...
: Paul: Thanks for the help.
<snip
: Unfortunately, when I copy your version in, the VBE highlights TEXT and
pops
: up an error saying "Expected end of statement"??? (I did put it all on
one
: line.)
<snip

Interesting indeed. I tried to copy the code and got the same error. It
appears during copy that a " is inserted when pasting (not sure why). Make
sure you have
ws.Range("E1").Formula = "= ""AR"" & RIGHT(YEAR(B1),2) & TEXT...
and not
ws.Range("E1").Formula = "= ""AR"" & RIGHT(YEAR(B1),2) &"TEXT...

notice the quote (") after the &, make sure it is not there
Paul D


  #7   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default WS formula for Julian date not converting well to VBA??

Worked perfectly, Paul! Thank you. Wonder if the extra quote had something
to do with pasting it directly into the VBE and then taking out the line
break. This time, I pasted into Word, took out the line break, then pasted
the single line into the module - no quotes.

Ed

"PaulD" <nospam wrote in message
...
"Ed" wrote in message
...
: Paul: Thanks for the help.
<snip
: Unfortunately, when I copy your version in, the VBE highlights TEXT and
pops
: up an error saying "Expected end of statement"??? (I did put it all on
one
: line.)
<snip

Interesting indeed. I tried to copy the code and got the same error. It
appears during copy that a " is inserted when pasting (not sure why). Make
sure you have
ws.Range("E1").Formula = "= ""AR"" & RIGHT(YEAR(B1),2) & TEXT...
and not
ws.Range("E1").Formula = "= ""AR"" & RIGHT(YEAR(B1),2) &"TEXT...

notice the quote (") after the &, make sure it is not there
Paul D




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
Formula to show when the julian date changes m1tell Excel Discussion (Misc queries) 1 April 19th 08 01:03 AM
Converting a date to a text field w/o converting it to a julian da LynnMinn Excel Worksheet Functions 2 March 6th 08 03:43 PM
converting julian day and year to a date? Chad Nordberg Excel Worksheet Functions 1 February 27th 06 10:23 PM
Excel should have a formula for Converting Julian Dates Yakimeshi Excel Worksheet Functions 0 May 17th 05 06:23 PM
Excel should have a formula for Converting Julian Dates Peo Sjoblom Excel Worksheet Functions 0 May 17th 05 06:15 PM


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