LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default Insert Dynamic Formula

I have date values going down column 1 as shown in "Example 1". I'm trying
to write code that will go down each cell in column 1 and insert a dynamic
formula in column 2. My code in "CODE 1" below will insert the correct range
in each cell in column 2, but when I try to insert the "YEAR()" formula in
column 2 for each cell, it inserts the correct formula as shown in Example 2
below, but excel displays the value of the "=YEAR(RC[-1])" formula as
"6/30/1905" instead of "2008".

How can I modify CODE 2 below so for example, cell B1 would equal 2008,
instead of 6/30/1905? As I stated, after running CODE 2 below, the formulas
look like Example 2 below which look correct, but display 6/30/1905 instead
of returning 2008 for the year formula result.



CODE 1: *****************

Set c = ActiveSheet.Range("A1")
Do While c < ""
c.Offset(0, 1).Formula = "=RC[-1]"
'set c to the next cell down
Set c = c.Offset(1, 0)
Loop

CODE 2: *****************

Set c = ActiveSheet.Range("A1")
Do While c < ""
c.Offset(0, 1).Formula = "=YEAR(RC[-1])"
'set c to the next cell down
Set c = c.Offset(1, 0)
Loop


Example 1
*******************

A B
1 6/1/2008
2 7/1/2008
3 8/1/2008




Example 2
*******************

A B
1 6/1/2008 =YEAR(A1)
2 7/1/2008 =YEAR(A2)
3 8/1/2008 =YEAR(A3)

 
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
Insert dynamic formula Ray Excel Programming 1 March 26th 07 10:22 PM
Help with copying dynamic column selected based on remote cell value and dynamic formula fill ers Charts and Charting in Excel 0 March 1st 06 01:05 AM
Help with copying dynamic column selected based on remote cell value and dynamic formula fill ers Excel Programming 0 March 1st 06 01:05 AM
Dynamic Range with unused formula messing up x axis on dynamic graph [email protected] Charts and Charting in Excel 2 February 2nd 06 08:02 PM


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