View Single Post
  #14   Report Post  
Posted to microsoft.public.excel.programming
Dana DeLouis Dana DeLouis is offline
external usenet poster
 
Posts: 947
Default How do I make this code shorter? Its Result should be given tovar

C = 3 * Int((Cl + 4) / 3) - 2

Slightly better might be just an offset equation...

Sub Try2()
Dim Rw As Long
Dim Cl As Long
Dim C As Long

Rw = ActiveCell.Row
Cl = ActiveCell.Column

If Not (Rw = 2 And Rw <= 12 And _
Cl = 2 And Cl <= 22) Then Exit Sub

'// Offset by 2,1,or 0
C = Cl + 2 - (Cl + 1) Mod 3

'// Fill in Formula down to row 12
Range(Cells(Rw, C), Cells(12, C)).FormulaR1C1 = "=RC[-2]+RC[-1]"
End Sub

- - -
HTH :)
Dana DeLouis