1

This line shows a runtime error 1004, but I don't understand why:

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
Mathieu Guindon
  • 69,817
  • 8
  • 107
  • 235
Anna
  • 11
  • 1

2 Answers2

2

The issue is that vba is very US-English centric. So either use , in place of ; or use .FormulaR1C1Local:

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

See here on how to avoid using .Select and why.

Community
  • 1
  • 1
Scott Craner
  • 148,073
  • 10
  • 49
  • 81
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

Two changes were made:

  1. Usage of FormulaR1C1 instead of Formula.
  2. Replacing the ; in the formulas for ,.
Ralph
  • 9,284
  • 4
  • 32
  • 42