Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

easy formula question

Status
Not open for further replies.

tabaki

Programmer
Nov 14, 2001
19
BE
Hi, I am a newby and therefor this rather easy question but I don't seem to solve this issue

I want to create a for loop in which I want to paste for each row the folowing formula:
if(row K = ""; ""; row K * row K)

the code :
for row = begin to end
formula= "=if( & row & "K = \"\"; \"\";" & row & "K *" & row & "L)"
cells(row,5)= formula
next i

can anywone tell me how I have to create this formula in VBA
 


Hi,

You didn'tsay what COLUMN the formula is assigned in. I assumed Column Z. I als assume that you are using European nototion in your formula, using ; rather than , ...
[tt]
=IF(expression;TRUE result;FALSE result)
[/tt]
Code:
 for i = begin to end
'    if(row K = ""; ""; row K * row K)
     cells(i, "Z").formula= "=if(K" & i & " = """"; """";K" & i& "*K" & i & ")" 
     cells(row,5)= formula
next i

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hi skip

thank you very much for your answer but I still can't create this formula

what you were assuming is true, my notation is ";" in the IF-formula
I assume when you want to interpretate the character " litterally you should place it twice.

I have simplified my formula and it still won't work:
Cells(81, "J").Formula = "=if(i81>0;0;1)"

but the following gives no problems, the string underneathn will just be printed, the formula isn't active:
Cells(81, "J").Formula = "if(i81>0;0;1)"

 


What is i supposed to be?
Code:
Cells(81, "J").Formula = "=if([b]i[/b]81>0;0;1)"


Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Anyway, VBA isn't localized:
Cells(81, "J").Formula = "=if(i81>0,0,1)"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you very much PHV, it was indeed the solution: although in the formula on the excel page the ";" characters appear I have to use "," characters in VBA...

strange...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top