Problème macro : mimatch des types et utilisation de fonctions excel en VBA

elmomo

XLDnaute Nouveau
Bonjour,

J'ai un problème avec le code ci-dessous, je n'arrive pas à faire calculer la variable "correction" (que j'ai mis en variant pour plus de simplicité).

Le but du programme (c'est assez chiant) est de repérer des "sauts" dans un tableau (la première ligne), et quand ce "saut" est repéré, de calculer le rapport (moyenne colonne de gauche jusqu'au saut)/(moyenne colonne de droite jusqu'au prochain saut) -que j'ai simplifié en me contentant de rajouter 50 lignes, on compliquera ptet plus tard- puis d'utliser cette "correction" en tant que multiplicateur pour une autre colonne, et enfin d'afficher le résultat dans une dernière colonne.

Si vous avez suivi jusqu'ici, bravo.

Bref, la macro en elle-même tourne, mais je n'arrive pas à utiliser la fonction average pour calculer "correction".

J'ai un peu fouillé, voir les formules en commentaires, mais jusqu'ici, aucune ne marche... Je pense que c'est un problème de définition ou de syntaxe, mais je n'arrive pas à l'identifier...

Merci de votre aide !

Sub retraitement_série_itrxig()

Dim a, col, i, j, colmax, copycol, b As Integer
Dim correction, plage, value1, value2 As Variant


a = 9
col = Range("v1").Column
colmax = Range("af1").Column
copycol = Range("bf1").Column
b = a
correction = 1

For a = 9 To 1268

If WorksheetFunction.IsNA(Cells(a, col + 1)) And WorksheetFunction.IsNumber(Cells(a + 1, col + 1)) Then
'plage = Range(Cells(b, col), Cells(a, col))

'correction = ("=AVERAGE(" & Cells(b, col).Address & ":" & Cells(a, col).Address & ")" / "=AVERAGE(" & Cells(a + a, col + 1).Address & ":" & Cells(a, col + 1).Address & ")")

'correction = Application.WorksheetFunction.Average(Range(Cells(b, col) & ":" & Cells(a, col))) / (Application.WorksheetFunction.Average(Range(Cells(a + a, col + 1) & ":" & Cells(a, col + 1))))
'((Cells(a - 2, col) + Cells(a - 1, col) + Cells(a, col) / 3) / (Cells(a, col + 1) + Cells(a + 1, col + 1) + Cells(a + 2, col + 2)) / 3)

'correction = (WorksheetFunction.Sum(Range(Cells(b, col) & ":" & Cells(a, col)) / (a - b)) / (WorksheetFunction.Sum(Range(Cells(a + a, col + 1) & ":" & Cells(a, col + 1))) / a))

'correction = (("=sum(" & Cells(b, col).Address & ":" & Cells(a, col).Address & ")" / (a - b)) / ("=sum(" & Cells(a + 50, col + 1).Address & ":" & Cells(a, col + 1).Address & ")") / 50)

For j = b To a

value2 = Cells(b, copycol).Value
value1 = value2 * correction
Cells(b, copycol + 1) = value1

Next j

End If

Next a
col = col + 1
b = a

End Sub

PS : vous l'aurez peut etre deviné, je bosse en anglais^^.
 
Dernière édition:

Discussions similaires

Statistiques des forums

Discussions
312 304
Messages
2 087 067
Membres
103 451
dernier inscrit
Souleymane