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

I need to extract the year only in a cell from the date in another cell.
What I have tried is:

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

I get an error which reads: Compile error:
--
Linda
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 373
Default Year date format

Activecell.Formula="=YEAR(B4)"

"mathel" wrote in message
...
I need to extract the year only in a cell from the date in another cell.
What I have tried is:

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

I get an error which reads: Compile error:
--
Linda



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Year date format

I somehow lost the entire macro in the file I was working on. I now have to
wait until our IT people can restore it to try your resolution to the
problem. I will post a 'Yes' or 'No' once I have tested my document.

Thanks for the quick response.
--
Linda


"Zone" wrote:

Activecell.Formula="=YEAR(B4)"

"mathel" wrote in message
...
I need to extract the year only in a cell from the date in another cell.
What I have tried is:

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

I get an error which reads: Compile error:
--
Linda




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Year date format

Hi,

I input the line exactly as shown below, then run my macro. The results I
get are the cell shows: #NAME?

When I look at the actual formula it appears as: =YEAR('B4').
How do I get rid of the single quote around B4?

Thanks
--
Linda


"Zone" wrote:

Activecell.Formula="=YEAR(B4)"

"mathel" wrote in message
...
I need to extract the year only in a cell from the date in another cell.
What I have tried is:

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

I get an error which reads: Compile error:
--
Linda




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Year date format

Zone used: Activecell.Formula = ...
I suspect you're still using: ActiveCell.FormulaR1C1 = ...

Try using Activecell.Formula instead.

mathel wrote:

Hi,

I input the line exactly as shown below, then run my macro. The results I
get are the cell shows: #NAME?

When I look at the actual formula it appears as: =YEAR('B4').
How do I get rid of the single quote around B4?

Thanks
--
Linda

"Zone" wrote:

Activecell.Formula="=YEAR(B4)"

"mathel" wrote in message
...
I need to extract the year only in a cell from the date in another cell.
What I have tried is:

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

I get an error which reads: Compile error:
--
Linda





--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Year date format

I did not leave a space between ActiveCell.Formula="YEAR(B4)". I tried it
again, with a space. The results I obtained in the cell were 1905. The
exact code I am using is as follows:

Range("B4").Select
ActiveCell.FormulaR1C1 = "=TODAY()"

Range("J4").Select
ActiveCell.Formula = "=YEAR(B4)"

As stated, this gives me a result of 1905 in cell J4.

Thanks for your help
--
Linda


"Dave Peterson" wrote:

Zone used: Activecell.Formula = ...
I suspect you're still using: ActiveCell.FormulaR1C1 = ...

Try using Activecell.Formula instead.

mathel wrote:

Hi,

I input the line exactly as shown below, then run my macro. The results I
get are the cell shows: #NAME?

When I look at the actual formula it appears as: =YEAR('B4').
How do I get rid of the single quote around B4?

Thanks
--
Linda

"Zone" wrote:

Activecell.Formula="=YEAR(B4)"

"mathel" wrote in message
...
I need to extract the year only in a cell from the date in another cell.
What I have tried is:

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

I get an error which reads: Compile error:
--
Linda




--

Dave Peterson

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Year date format

Glad you got it fixed.

You can accomplish the same kind of thing without the .select's:

Range("B4").FormulaR1C1 = "=TODAY()"
Range("J4").Formula = "=YEAR(B4)"

or even

with worksheets("Somesheetnamehere")
.Range("B4").Formula = "=TODAY()"
with .range("J4")
.numberformat = "General"
.Formula = "=YEAR(B4)"
end with
end with



mathel wrote:

I did not leave a space between ActiveCell.Formula="YEAR(B4)". I tried it
again, with a space. The results I obtained in the cell were 1905. The
exact code I am using is as follows:

Range("B4").Select
ActiveCell.FormulaR1C1 = "=TODAY()"

Range("J4").Select
ActiveCell.Formula = "=YEAR(B4)"

As stated, this gives me a result of 1905 in cell J4.

Thanks for your help
--
Linda

"Dave Peterson" wrote:

Zone used: Activecell.Formula = ...
I suspect you're still using: ActiveCell.FormulaR1C1 = ...

Try using Activecell.Formula instead.

mathel wrote:

Hi,

I input the line exactly as shown below, then run my macro. The results I
get are the cell shows: #NAME?

When I look at the actual formula it appears as: =YEAR('B4').
How do I get rid of the single quote around B4?

Thanks
--
Linda

"Zone" wrote:

Activecell.Formula="=YEAR(B4)"

"mathel" wrote in message
...
I need to extract the year only in a cell from the date in another cell.
What I have tried is:

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

I get an error which reads: Compile error:
--
Linda




--

Dave Peterson


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Year date format

I just posted a reply indicating there was still a problem - I just figured
it out. I had formatted cell J4 to Custom formatting as 'yyyy'. When I ran
the macro with

Range("J4").Select
ActiveCell.Formula = "=YEAR(B4)"

I was getting the result of 1905. I have now formatted the cell as number
and now get the correct response.

Thanks for all you assistance.
Linda


"Dave Peterson" wrote:

Zone used: Activecell.Formula = ...
I suspect you're still using: ActiveCell.FormulaR1C1 = ...

Try using Activecell.Formula instead.

mathel wrote:

Hi,

I input the line exactly as shown below, then run my macro. The results I
get are the cell shows: #NAME?

When I look at the actual formula it appears as: =YEAR('B4').
How do I get rid of the single quote around B4?

Thanks
--
Linda

"Zone" wrote:

Activecell.Formula="=YEAR(B4)"

"mathel" wrote in message
...
I need to extract the year only in a cell from the date in another cell.
What I have tried is:

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

I get an error which reads: Compile error:
--
Linda




--

Dave Peterson

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
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
I need date format to be set up as month/year. Aaron New Users to Excel 2 December 22nd 05 01:46 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 02:13 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"