Question : VB FORMULA - Loop

With the below code what I'm trying to do is on the first run it applies  the IF is 1st row then applies the If Is not 1st Row.

Does anyone know if this is possible or if there is an easier way to show this expression
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
Sheets("Input").Activate
    ' Init
Set sht = ActiveSheet

    ' Set Range
Set rng1 = Range([be38], [be38].End(xlDown))

    ' Apply Formula
''rng1.Offset(0, 2).CurrentArray.Resize(rng1.Rows.Count, 7).FormulaArray = "=MAX((RC5=Process!R2C5:R65536C5)*Process!R2C15:R65536C15)"

Index = 0
For Each c In rng1
  With c
    If .EntireRow.Hidden Or .EntireColumn.Hidden Then
      Else
        If c.Address <> rng1(rng1.Count).Address Then
          'If is 1st Row
                rng1.Offset(0, 2).FormulaR1C1 = "=RC53"
                rng1.Offset(0, 3).FormulaR1C1 = "=R[1]C53"
                rng1.Offset(0, 4).FormulaR1C1 = "=R[2]C53"
                rng1.Offset(0, 5).FormulaR1C1 = "=R[3]C53"
                rng1.Offset(0, 6).FormulaR1C1 = "=R[4]C53"
                rng1.Offset(0, 7).FormulaR1C1 = "=R[5]C53"
                rng1.Offset(0, 8).FormulaR1C1 = "=R[6]C53"
          Else
          'If IS not 1st Row
                rng1.Offset(0, 2).FormulaR1C1 = "=R[" & CStr(0 + Index) & "]53"
                rng1.Offset(0, 3).FormulaR1C1 = "=R[" & CStr(1 + Index) & "]C53"
                rng1.Offset(0, 4).FormulaR1C1 = "=R[" & CStr(2 + Index) & "]C53"
                rng1.Offset(0, 5).FormulaR1C1 = "=R[" & CStr(3 + Index) & "]C53"
                rng1.Offset(0, 6).FormulaR1C1 = "=R[" & CStr(4 + Index) & "]C53"
                rng1.Offset(0, 7).FormulaR1C1 = "=R[" & CStr(5 + Index) & "]C53"
                rng1.Offset(0, 8).FormulaR1C1 = "=R[" & CStr(6 + Index) & "]C53"
        End If
        Index = Index + 6
    End If
  End With
Next c

Answer : VB FORMULA - Loop

sjvenz,

Something like the code below.

Patrick
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
Sub looper()
Dim sht As Worksheet
Dim rng1 As Range
Dim celle As Range
Dim counter As Long
Dim i As Long

Set sht = Sheets("Input")
sht.Activate
Set rng1 = sht.Range([be38], [be38].End(xlDown))
counter = 0
i = 1
For Each celle In rng1
    If i = 1 Then
        rng1.Offset(0, 2).FormulaR1C1 = "=RC53"
        rng1.Offset(0, 3).FormulaR1C1 = "=R[1]C53"
        rng1.Offset(0, 4).FormulaR1C1 = "=R[2]C53"
        rng1.Offset(0, 5).FormulaR1C1 = "=R[3]C53"
        rng1.Offset(0, 6).FormulaR1C1 = "=R[4]C53"
        rng1.Offset(0, 7).FormulaR1C1 = "=R[5]C53"
        rng1.Offset(0, 8).FormulaR1C1 = "=R[6]C53"
        i = i + 1
    Else
        'If IS not 1st Row
        rng1.Offset(0, 2).FormulaR1C1 = "=R[" & CStr(0 + counter) & "]53"
        rng1.Offset(0, 3).FormulaR1C1 = "=R[" & CStr(1 + counter) & "]C53"
        rng1.Offset(0, 4).FormulaR1C1 = "=R[" & CStr(2 + counter) & "]C53"
        rng1.Offset(0, 5).FormulaR1C1 = "=R[" & CStr(3 + counter) & "]C53"
        rng1.Offset(0, 6).FormulaR1C1 = "=R[" & CStr(4 + counter) & "]C53"
        rng1.Offset(0, 7).FormulaR1C1 = "=R[" & CStr(5 + counter) & "]C53"
        rng1.Offset(0, 8).FormulaR1C1 = "=R[" & CStr(6 + counter) & "]C53"
    End If
    counter = counter + 6
Next celle
End Sub
Random Solutions  
 
programming4us programming4us