View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Function Program

Sounds like you want

For i = 8 To Cells(Rows.Count,"C").End(xlUp).Row
Range("C"& i).FormulaR1C1 =
"=IF(RC[-1]=0,"""",(100-(((R[-" & i - 5 & "]C-RC[-1])/R[-" & i - 5 &
"]C)*100)))"
Next i

--

HTH

RP
(remove nothere from the email address if mailing direct)


"maperalia" wrote in message
...
Please I need your help to adjust my program.
I have the following program (see below) that I want to make it generic.

As
you will notice this program works for specific number of cells. However,

my
new sheet has two hundred cells more and I want to avoid add more lines in

my
program.
Do you think is possible to make it generic for numbers of cells at
anytime?...
I will really appreciate your helping me....

Maperalia
------------------------------------------------------------

Sub Calculation()

'Apply formula in each cell at Column "C"
Range("C8").Select
ActiveCell.FormulaR1C1 =
"=IF(RC[-1]=0,"""",(100-(((R[-3]C-RC[-1])/R[-3]C)*100)))"
Range("C9").Select
ActiveCell.FormulaR1C1 =
"=IF(RC[-1]=0,"""",(100-(((R[-4]C-RC[-1])/R[-4]C)*100)))"
Range("C10").Select
ActiveCell.FormulaR1C1 =
"=IF(RC[-1]=0,"""",(100-(((R[-5]C-RC[-1])/R[-5]C)*100)))"
Range("C11").Select
ActiveCell.FormulaR1C1 =
"=IF(RC[-1]=0,"""",(100-(((R[-6]C-RC[-1])/R[-6]C)*100)))"
Range("C12").Select
ActiveCell.FormulaR1C1 =
"=IF(RC[-1]=0,"""",(100-(((R[-7]C-RC[-1])/R[-7]C)*100)))"
Range("C13").Select
ActiveCell.FormulaR1C1 =
"=IF(RC[-1]=0,"""",(100-(((R[-8]C-RC[-1])/R[-8]C)*100)))"
Range("C14").Select
ActiveCell.FormulaR1C1 =
"=IF(RC[-1]=0,"""",(100-(((R[-9]C-RC[-1])/R[-9]C)*100)))"
Range("C8").Select

'Apply additional formula in each cell at Column "D"
Range("D8").Select
ActiveCell.FormulaR1C1 = "=100-RC[-1]"
Range("D8").Select
Selection.AutoFill Destination:=Range("D8:D14"), Type:=xlFillDefault
Range("D8:D14").Select
Range("D8").Select
End Sub