Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default Inserting formula

You can do it in one operation, like so

Range("M1:N25").Formula="=IF($Q198=R$37,$N198,0)"

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"Antonio" wrote in message
...
I need to insert programmatically the following formula in several adjacent
cells

=IF($Q198=R$37,$N198,0)

198 is the row number that varies
R is the column letter that varies

The rest is constant

I cannot copy the cells from above because sometimes I am not supposed to.
Copying the cells from above manually does work.

I am trying:

.Cells(r, 18).Formula = "=IF($Q" & r & "=" & Column() & "$37" & ",$N" & r
&
",0)"

where r is the row number
I need to figure out the column()



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default Inserting formula

You can also use R1C1 notation

.Range(Cells(ct, 18), .Cells(ct, 23)).FormulaR1C1 =
"=IF(RC17=R37C,RC14,0)"


--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"Antonio" wrote in message
...
Hi Bob,

Your solution looks powerful,

I have

.Cells(ct, 18).FormulaR1C1 = "=IF(RC17=R37C,RC14,0)"
.Cells(ct, 19).FormulaR1C1 = "=IF(RC17=R37C,RC14,0)"
.Cells(ct, 20).FormulaR1C1 = "=IF(RC17=R37C,RC14,0)"
.Cells(ct, 21).FormulaR1C1 = "=IF(RC17=R37C,RC14,0)"
.Cells(ct, 22).FormulaR1C1 = "=IF(RC17=R37C,RC14,0)"
.Cells(ct, 23).FormulaR1C1 = "=IF(RC17=R37C,RC14,0)"

How do I use your way?

.Range(Cells(ct, 18), Cells(ct, 23)).Formula = "=IF($Q198=R$37,$N198,0)"

does not work, obviously.



"Bob Phillips" wrote:

You can do it in one operation, like so

Range("M1:N25").Formula="=IF($Q198=R$37,$N198,0)"

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"Antonio" wrote in message
...
I need to insert programmatically the following formula in several
adjacent
cells

=IF($Q198=R$37,$N198,0)

198 is the row number that varies
R is the column letter that varies

The rest is constant

I cannot copy the cells from above because sometimes I am not supposed
to.
Copying the cells from above manually does work.

I am trying:

.Cells(r, 18).Formula = "=IF($Q" & r & "=" & Column() & "$37" & ",$N" &
r
&
",0)"

where r is the row number
I need to figure out the column()






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
Inserting Formula vcprabhu Excel Discussion (Misc queries) 1 April 6th 09 06:55 AM
Inserting formula Alok Excel Programming 0 December 14th 06 08:27 PM
inserting formula davegb Excel Programming 11 April 27th 06 02:52 PM
inserting a formula dstiefe Excel Discussion (Misc queries) 6 August 10th 05 09:33 PM
Formula changes while inserting a row !!!! Sanjeev Unnikrishnan Excel Worksheet Functions 3 April 16th 05 02:45 PM


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