VBA Issue - Sum If Function

Solved
Bonjour,

I am trying to create a VBA code using the "SumIfs" function.

The idea is for my function to sum the values in column B if the values in column A of sheet 1 are included in a range of values defined in sheet 2.

I will include at the end of the message the code I have already written.

The problem is that when I run my code step by step to check its operation, when I reach the line where I defined my "SumIfs" function, VBA returns me an "Execution error '1004': Application-defined or object-defined error".

I would be very grateful for the time you take to take a look...

Thank you in advance,

Best regards,

Below is my code.

Sub PassageTiers()

Dim w As Integer 'Fine column
Dim x As Integer 'Third column
Dim nbrfichier As Integer
Dim nbrfreq As Integer
Dim valtiers As Double

nbrfichier = 39
nbrfreq = 193
w = 1

Do Until w = nbrfichier + 1

w = w + 1

Do Until x = 29

x = 3

valtiers = Application.WorksheetFunction.SumIfs(Worksheets("Résultats_Bandes_Fines").Range(Cells(2, w), Cells(nbrfreq + 1, w)), Worksheets("Résultats_Bandes_Fines").Range(Cells(2, 1), Cells(nbrfreq + 1, 1)), "" > "" & Worksheets("Résultats_Tiers_Oct").Cells(2, x), Worksheets("Résultats_Bandes_Fines").Range(Cells(2, 1), Cells(nbrfreq + 1)), "" <= "" & Worksheets("Résultats_Tiers_Oct").Cells(3, x))
Worksheets("Résultats_Tiers_Oct").Cells(w + 3, x) = valtiers

x = x + 1
valtiers = 0

Loop
Loop
End Sub

3 answers

  • Votes
  • Date
  • Descending date