Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Macro to insert formula failing...need help

Hi,

I am trying to make a macro to insert a column then do an autofill with
a formula. I have:

Sub calculateage()

Rows("1:1").Select
Selection.Delete Shift:=xlUp
Selection.Insert Shift:=xlDown
Range("H1").Select
ActiveCell.FormulaR1C1 = "=TODAY()"


Range("AU1").Select
ActiveCell.FormulaR1C1 = "=int((TODAY()-H1)/365.25)"
Selection.AutoFill Destination:=Range("AU2:AU20000"),
Type:=xlFillDefault

End Sub

However, this line doesn't work:
Selection.AutoFill Destination:=Range("AU2:AU20000"),
Type:=xlFillDefault

I got it working but when it did work it inserted H1 from the formula
on every line when I need it to run down H1, h2, h3, ect. Any ideas of
what might be going on?

The spreadsheet has people's date of birth in column H. I need to add
a column that will calculate their age. (then it will need to total
out how many people in different age groups but I'm not to that point
yet)

Thank you in advance,
Mary

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default Macro to insert formula failing...need help

..FormulaR1C1 and H1 conflict with each other.
Use .Formula or use RC[-39] as address

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"Dagonini" wrote in message oups.com...
| Hi,
|
| I am trying to make a macro to insert a column then do an autofill with
| a formula. I have:
|
| Sub calculateage()
|
| Rows("1:1").Select
| Selection.Delete Shift:=xlUp
| Selection.Insert Shift:=xlDown
| Range("H1").Select
| ActiveCell.FormulaR1C1 = "=TODAY()"
|
|
| Range("AU1").Select
| ActiveCell.FormulaR1C1 = "=int((TODAY()-H1)/365.25)"
| Selection.AutoFill Destination:=Range("AU2:AU20000"),
| Type:=xlFillDefault
|
| End Sub
|
| However, this line doesn't work:
| Selection.AutoFill Destination:=Range("AU2:AU20000"),
| Type:=xlFillDefault
|
| I got it working but when it did work it inserted H1 from the formula
| on every line when I need it to run down H1, h2, h3, ect. Any ideas of
| what might be going on?
|
| The spreadsheet has people's date of birth in column H. I need to add
| a column that will calculate their age. (then it will need to total
| out how many people in different age groups but I'm not to that point
| yet)
|
| Thank you in advance,
| Mary
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro to insert formula failing...need help

Hi Mary...

why donīt you use the formula "datedif(birth_date; today(); "M" | "Y"
| "D" ) ???

the parameters:
"M" if you want get the result in months
"Y" if you want the result in years
"D" if you want the result in days

I use it like this:

ActiveCell.FormulaR1C1 =
"=DATEDIF(RC[-2],TODAY(),""M"")-(PRODUCT(RC[-1],12))"
Columns("O:O").Select
Range("O2").Select
Selection.AutoFill Destination:=Range("O2:O2500"),
Type:=xlFillDefault

Bye!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Macro to insert formula failing...need help

Range("AU1:AU20000").Formula = "=INT((TODAY()-H1)/365.25)"

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Dagonini" wrote in message
oups.com...
Hi,

I am trying to make a macro to insert a column then do an autofill with
a formula. I have:

Sub calculateage()

Rows("1:1").Select
Selection.Delete Shift:=xlUp
Selection.Insert Shift:=xlDown
Range("H1").Select
ActiveCell.FormulaR1C1 = "=TODAY()"


Range("AU1").Select
ActiveCell.FormulaR1C1 = "=int((TODAY()-H1)/365.25)"
Selection.AutoFill Destination:=Range("AU2:AU20000"),
Type:=xlFillDefault

End Sub

However, this line doesn't work:
Selection.AutoFill Destination:=Range("AU2:AU20000"),
Type:=xlFillDefault

I got it working but when it did work it inserted H1 from the formula
on every line when I need it to run down H1, h2, h3, ect. Any ideas of
what might be going on?

The spreadsheet has people's date of birth in column H. I need to add
a column that will calculate their age. (then it will need to total
out how many people in different age groups but I'm not to that point
yet)

Thank you in advance,
Mary



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
Failing with formula Charlie Excel Discussion (Misc queries) 8 August 5th 09 02:54 PM
Advanced Filter Macro Failing Mustang Excel Discussion (Misc queries) 3 June 18th 09 05:15 AM
Excel Macro Security Failing JayCl Excel Discussion (Misc queries) 0 September 28th 06 04:11 PM
changelink macro failing. Prior link is to a non existent file. whylite Excel Programming 4 February 19th 06 04:36 PM
Macro failing Syd[_3_] Excel Programming 0 September 17th 03 02:51 PM


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