Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Year Date Format

Sorry, I hit Post on the previous question accidently.....

To repeat, I am trying to extract the year only in a cell based on the date
in another cell. What I have in vba is:

Range("J4").Select
ActiveCell.FormulaR1C1 = "=text(b4, "yyyy")"

This returns an error: Compile Error: Expected: end of statement

What am I doing wrong.

Thanks
--
Linda
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Year Date Format

Range("J4").Formula = "=text(b4, ""yyyy"")"

When working with formula in VBA, one good apporach is to get the formula working, trurn on macro
recording, select the cell, press F2 and enter, then stop recording, and look at the code. That will
handle the double quotes (which need to be doubled within a formula) correctly.

HTH,
Bernie
MS Excel MVP


"mathel" wrote in message
...
Sorry, I hit Post on the previous question accidently.....

To repeat, I am trying to extract the year only in a cell based on the date
in another cell. What I have in vba is:

Range("J4").Select
ActiveCell.FormulaR1C1 = "=text(b4, "yyyy")"

This returns an error: Compile Error: Expected: end of statement

What am I doing wrong.

Thanks
--
Linda



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default Year Date Format

You have used the FormulaR1C1 property, which expects the range in R1C1
notation, BUT you used A1 notation in the formula. You should use

ActiveCell.Formula = "=TEXT(B4,"yyyy")"

not FormulaR1C1.


On Mon, 5 Nov 2007 05:17:03 -0800, mathel
wrote:

Sorry, I hit Post on the previous question accidently.....

To repeat, I am trying to extract the year only in a cell based on the date
in another cell. What I have in vba is:

Range("J4").Select
ActiveCell.FormulaR1C1 = "=text(b4, "yyyy")"

This returns an error: Compile Error: Expected: end of statement

What am I doing wrong.

Thanks

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
Year date format mathel Excel Programming 7 November 6th 07 09:20 PM
Format date with just month and year Jay3253 Excel Discussion (Misc queries) 6 February 2nd 06 07:17 PM
date format, looking for a date in column A that is one year ago mike Excel Programming 1 December 30th 05 04:41 PM
day/month/year in incorrect format for date format M&A_Jack Excel Worksheet Functions 2 August 16th 05 08:15 PM
Month Year Date Format Jamie Excel Worksheet Functions 2 February 7th 05 06:43 PM


All times are GMT +1. The time now is 04:50 AM.

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

About Us

"It's about Microsoft Excel"