VBA Issue - Sum If Function

Solved
Sizlacks Posted messages 15 Status Membre -  
Sizlacks Posted messages 15 Status Membre -
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 réponses

yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   Ambassadeur 1 588
 
Hello, can you use code tags to share code: https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code

Have you tried calculating this in VBA instead of using a formula?
0
Sizlacks Posted messages 15 Status Membre
 
Hello,

what type of tag should I use for VBA code...? "Basic"? "xml"?
I started learning VBA two days ago, I'm not very familiar with it yet!
0
yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   1 588 > Sizlacks Posted messages 15 Status Membre
 
basic, indeed.
0