Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Member
 
Posts: 57
Default Macro to insert formula

I had a look through the forum but could not find what i need, can anyone out there help?
I have a sheet that works fine and am just fine tuning the last bits and I need a little help please.
There is a function =LOOKUP(K1,'AR7 calcs'!F22:F24,'AR7 calcs'!N22:N24) that as part of the sheet could possibly be overwritten in some circumstances so i want to reinsert it as part of a clear sheet macro I have written.
The macro Range("I13:J13").Select
ActiveCell.FormulaR1C1 = "=LOOKUP(K1,'AR7 calcs'!F22:F24,'AR7 calcs'!N22:N24)" leaves the formula as =LOOKUP('K1','AR7 calcs'!'F22':'F24','AR7 calcs'!'N22':'N24') and retuns a #name? error

How do I get the macro to input exactly the formula I need?

chers
nobby
  #2   Report Post  
Member
 
Posts: 57
Default

sussed
Range("i13:j13").Select
ActiveCell.FormulaR1C1 = _
"=LOOKUP(R[-9]C[4],'AR7 calcs'!R[12]C[-1]:R[16]C[-1],'AR7 calcs'!R[12]C[7]:R[16]C[7])"
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Dave Peterson
 
Posts: n/a
Default Macro to insert formula

If you're going to use .formulaR1C1, then your formula needs to use R1C1
reference style--not A1 reference style.

Maybe you can do what you want just using .formula????



nobbyknownowt wrote:

I had a look through the forum but could not find what i need, can
anyone out there help?
I have a sheet that works fine and am just fine tuning the last bits
and I need a little help please.
There is a function =LOOKUP(K1,'AR7 calcs'!F22:F24,'AR7 calcs'!N22:N24)
that as part of the sheet could possibly be overwritten in some
circumstances so i want to reinsert it as part of a clear sheet macro I
have written.
The macro Range("I13:J13").Select
ActiveCell.FormulaR1C1 = "=LOOKUP(K1,'AR7 calcs'!F22:F24,'AR7
calcs'!N22:N24)" leaves the formula as =LOOKUP('K1','AR7
calcs'!'F22':'F24','AR7 calcs'!'N22':'N24') and retuns a #name? error

How do I get the macro to input exactly the formula I need?

chers
nobby

--
nobbyknownowt


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
JonR
 
Posts: n/a
Default Macro to insert formula

Try this

Sub insert()

Dim x

For x = 1 To 2
Cells(13, x + 8).Activate
ActiveCell.Formula = "=LOOKUP(K1,'AR7 calcs'!F22:F24,'AR7 calcs'!N22:N24)"
Next x

End Sub



"nobbyknownowt" wrote:


I had a look through the forum but could not find what i need, can
anyone out there help?
I have a sheet that works fine and am just fine tuning the last bits
and I need a little help please.
There is a function =LOOKUP(K1,'AR7 calcs'!F22:F24,'AR7 calcs'!N22:N24)
that as part of the sheet could possibly be overwritten in some
circumstances so i want to reinsert it as part of a clear sheet macro I
have written.
The macro Range("I13:J13").Select
ActiveCell.FormulaR1C1 = "=LOOKUP(K1,'AR7 calcs'!F22:F24,'AR7
calcs'!N22:N24)" leaves the formula as =LOOKUP('K1','AR7
calcs'!'F22':'F24','AR7 calcs'!'N22':'N24') and retuns a #name? error

How do I get the macro to input exactly the formula I need?

chers
nobby


--
nobbyknownowt

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
Macro or Custom button to fill in the same formula TJ Excel Worksheet Functions 4 March 15th 06 10:33 PM
Match then lookup Tenacity Excel Worksheet Functions 9 December 3rd 05 05:30 AM
Insert New Row without shifting formula DJ Excel Worksheet Functions 2 September 26th 05 03:31 AM
Formula for current month minus one = Quarter number in a macro. Pank Excel Discussion (Misc queries) 11 June 22nd 05 02:47 PM
How do I insert the date using a macro tara0801 Excel Discussion (Misc queries) 4 February 10th 05 09:09 PM


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