2016-11-01 4 views
0

Ich muss in jede Zelle starten von Row 3Col 3 Ende in Row 3Col 32 eine andere Formel, 29 mal.VBA Automate FormulaR1C1

Wie kann ich diese Abfrage automatisieren, weil 29 eine Variable ist.

Range("C3").Select 
ActiveCell.FormulaR1C1 = _ 
    "=SUMIFS(Importat!C[6],Importat!C[-2],R2C3,Importat!C[5],RC[-2],Importat!C[-1],RC[-1])" 

Range("D3").Select 
ActiveCell.FormulaR1C1 = _ 
    "=SUMIFS(Importat!C[15],Importat!C[7],R2C4,Importat!C[14],RC[-3],Importat!C[8],RC[-2])" 

Range("E3").Select 
ActiveCell.FormulaR1C1 = _ 
    "=SUMIFS(Importat!C[24],Importat!C[16],R2C5,Importat!C[23],RC[-4],Importat!C[17],RC[-3])" 

Range("F3").Select 
ActiveCell.FormulaR1C1 = _ 
    "=SUMIFS(Importat!C[33],Importat!C[25],R2C6,Importat!C[32],RC[-5],Importat!C[26],RC[-4])" 

Range("G3").Select 
ActiveCell.FormulaR1C1 = _ 
    "=SUMIFS(Importat!C[42],Importat!C[34],R2C7,Importat!C[41],RC[-6],Importat!C[35],RC[-5])" 

Range("H3").Select 
ActiveCell.FormulaR1C1 = _ 
    "=SUMIFS(Importat!C[51],Importat!C[43],R2C8,Importat!C[50],RC[-7],Importat!C[44],RC[-6])" 

........... 

Range("AE3").Select 
ActiveCell.FormulaR1C1 = _ 
    "=SUMIFS(Importat!C[258],Importat!C[250],R2C32,Importat!C[257],RC[-30],Importat!C[251],RC[-29])" 

Antwort

2

versuchen Sie dies:

Dim i As Long 
With Range("C3") 
    For i = 1 To 29 
     .Offset(, i - 1).FormulaR1C1 = "=SUMIFS(Importat!C[" & 6 + (i - 1) * 9 & "],Importat!C[" & -2 + (i - 1) * 9 & "],R2C,Importat!C[" & 5 + (i - 1) * 9 & "],RC1,Importat!C[" & -1 + (i - 1) * 9 & "],RC2)" 
    Next i 
End With 
+0

große Werke. Vielen Dank – BOB