1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| Option Explicit
Sub average()
Dim wb As Workbook
Dim ws As Worksheet
Dim i As Integer, c As Integer
Dim Lastrow As Long, Lastcol As Long
Dim Nextcell As Double
Set wb = ThisWorkbook
Set ws = wb.Sheets("Sheet1") ' Change le nom de la feuille que tu utilise
Lastrow = ws.Range("A" & Rows.Count).End(xlUp).Row ' je suppose que les dates sont colones A
Lastcol = ws.Cells(1, Columns.Count).End(xlToLeft).Column
For c = 2 To Lastcol ' les rates commencent colonne B
For i = 1 To Lastrow
' Si la cellule est vide mais pas la suivante alors moyenne entre les 2
If IsEmpty(ws.Cells(i, c).Value) And Not IsEmpty(ws.Cells(i + 1, c).Value) Then
ws.Cells(i, c).Value = (ws.Cells(i - 1, c).Value + ws.Cells(i + 1, c).Value) / 2
' Si la cellule est vide et la suivante aussi alors il faut trouver la valeur suivant (Sub routine)
ElseIf IsEmpty(ws.Cells(i, c).Value) And IsEmpty(ws.Cells(i + 1, c).Value) Then
'Sub routine pour trouver le rate suivant qu'on appel Nextcell
NextProcess i, c, Nextcell
ws.Cells(i, c).Value = (ws.Cells(i - 1, c).Value + Nextcell) / 2
End If
Next i
Next c
End Sub |
Partager