FormulaR1C1

  • Thread starter Thread starter aapp81
  • Start date Start date
A

aapp81

the formula in question is:

Range("C2").Select
Selection.FormulaR1C1 = "=IF(RC2=""C"",RC1,0)"

and my code, unfortunately, looks like this:

Range("C2").Select
Selection.FormulaR1C1 = "=IF(RC2=""C"",RC1,0)"
Range("D2").Select
Selection.FormulaR1C1 = "=IF(RC2=""D"",RC1,0)"
Range("E2").Select
Selection.FormulaR1C1 = "=IF(RC2=""E"",RC1,0)"
Range("F2").Select
...and so on... until ("T2")

and my question is, what do i have to add so that i don't have to writ
the code for each cell

basically i'm looking for a For | Next operator that increases the A t
a B from col. C to D and so on...

sorry for the odd explanation..
 
try this

Sub ifalphabet()
Set Rng = Range("c2:t4")
Rng.Formula = "=IF($rc$2=CHAR(column(A1)+97+1),$rc$1,0)"
End Sub

--
Don Guillett
SalesAid Software
(e-mail address removed)
aapp81 said:
the formula in question is:

Range("C2").Select
Selection.FormulaR1C1 = "=IF(RC2=""C"",RC1,0)"

and my code, unfortunately, looks like this:

Range("C2").Select
Selection.FormulaR1C1 = "=IF(RC2=""C"",RC1,0)"
Range("D2").Select
Selection.FormulaR1C1 = "=IF(RC2=""D"",RC1,0)"
Range("E2").Select
Selection.FormulaR1C1 = "=IF(RC2=""E"",RC1,0)"
Range("F2").Select
..and so on... until ("T2")

and my question is, what do i have to add so that i don't have to write
the code for each cell

basically i'm looking for a For | Next operator that increases the A to
a B from col. C to D and so on...

sorry for the odd explanation...


------------------------------------------------



~~Now Available: Financial Statements.xls, a step by step guide to
creating financial statements
 
Sub test()

Dim intCol As Integer

For intCol = 3 To 20
Cells(2, intCol).FormulaR1C1 = "=IF(RC2=""" & Chr(intCol + 64) &
""",RC1,0)"
Next intCol

End Sub
 
Back
Top