2016-04-11 29 views
1

Diese Zeile zeigt einen Laufzeitfehler 1004, aber ich verstehe nicht, warum:VBA - Fehler 1004

ActiveCell.Formula = "=MATCH(R" & i & "C16;R" & i & "C6:R" & i & "C15;0)" 
Sub Call_Min() 

    Dim i As Integer 
    Dim limit As Integer 
    Sheets("AUX").Activate 
    limit = ActiveSheet.Range("B6").Value 

    Sheets("DATA").Activate 
    'ActiveSheet.Cells(6, 16).Select 
    'ActiveCell.Formula = "=SUM(Range("F6:I6"))" 
    For i = 6 To limit 

     'MATCH(P6;F6:O6;0) 
     ActiveSheet.Range("P" & i).Select 
     ActiveCell.Formula = "=MIN(R" & i & "C6:R" & i & "C15)" 

     ActiveSheet.Range("E" & i).Select 
     ActiveCell.Formula = "=MATCH(R" & i & "C16;R" & i & "C6:R" & i & "C15;0)" 
    Next i 

End Sub 
+1

Es sollte 'ActiveCell.FormulaR1C1' und nicht' ActiveCell.Formula' sein. – Ralph

+1

Ändern Sie 'ActiveCell.Formula' in' ActiveCell.FormulaR1C1Local ' –

Antwort

2

Das Problem, dass vba ist sehr US-Englisch-centric. Also entweder , anstelle von ; verwenden oder .FormulaR1C1Local verwenden:

Sub Call_Min() 
Dim i As Integer 
Dim limit As Integer 

limit = Sheets("AUX").Range("B6").Value 

Sheets("Sheet11").Activate 
'ActiveSheet.Cells(6, 16).Select 
'ActiveCell.Formula = "=SUM(Range("F6:I6"))" 
For i = 6 To limit 

     'MATCH(P6;F6:O6;0) 
     Sheets("DATA").Range("P" & i).FormulaR1C1Local = "=MIN(R" & i & "C6:R" & i & "C15)" 

     Sheets("DATA").Range("E" & i).FormulaR1C1Local = "=MATCH(R" & i & "C16;R" & i & "C6:R" & i & "C15;0)" 
Next i 
End Sub 

Siehe here auf, wie mit .Select und warum zu vermeiden.

+0

++, um' Select' und 'ActiveCell' zu vermeiden –

1
Sub Call_Min() 

    Dim i As Integer 
    Dim limit As Integer 
    Sheets("AUX").Activate 
    limit = ActiveSheet.Range("B6").Value 

    Sheets("DATA").Activate 
    'ActiveSheet.Cells(6, 16).Select 
    'ActiveCell.Formula = "=SUM(Range("F6:I6"))" 
    For i = 6 To limit 

     'MATCH(P6;F6:O6;0) 
     ActiveSheet.Range("P" & i).Select 
     ActiveCell.FormulaR1C1 = "=MIN(R" & i & "C6:R" & i & "C15)" 

     ActiveSheet.Range("E" & i).Select 
     ActiveCell.FormulaR1C1 = "=MATCH(R" & i & "C16,R" & i & "C6:R" & i & "C15,0)" 
    Next i 

End Sub 

Zwei Änderungen wurden vorgenommen:

  1. Verwendung von FormulaR1C1 statt Formula.
  2. Ersetzen Sie die ; in den Formeln für ,.
Verwandte Themen