Bonjour,
J'ai développé une macro qui tri une feuille en fonction de catégories spécifiées sur une autre feuille.
Quand je l’exécute, au bout d'un moment je me retrouve avec le message d'erreur "Out of Range" et je comprend pas du tout pourquoi.
Avez vous une idée ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 Sub reportingByModality() Application.DisplayAlerts = False With Sheets("raw_data") Dim category As String Dim lastCategory As String Dim modality As String Dim maxLineRawData As Long Dim maxLineModality As Long Dim cursor As Long category = "" lastCategory = "" maxLineModality = Sheets("Modality").Range("B65536").End(xlUp).Row maxLineRawData = Sheets("raw_data").Range("B65536").End(xlUp).Row For i = 2 To maxLineModality modality = Trim(Sheets("Modality").Range("A" & i).Value) category = Trim(Sheets("Modality").Range("B" & i).Value) If Replace(category, "/", "-") <> Replace(lastCategory, "/", "-") Then Application.ScreenUpdating = True 'On crée une nouvelle feuille category = Replace(category, "/", "-") Sheets.Add.Move After:=Sheets(Sheets.Count) Sheets(Sheets.Count).Name = category 'on copie l'entete Sheets("raw_data").Cells(1, "A").EntireRow.Copy Sheets(category).Cells(1, 1).Insert Shift:=xlDown Sheets(category).Range("A:CN").Columns.AutoFit Application.ScreenUpdating = False End If 'On parse la feuille raw data cursor = 2 For j = 1 To maxLineRawData If Trim(Sheets("raw_data").Range("CF" & j).Value) = Trim(modality) Then Sheets("raw_data").Cells(j, "A").EntireRow.Copy Sheets(category).Cells(cursor, 1).Insert Shift:=xlDown cursor = cursor + 1 End If Next j lastCategory = category Next i End With End Sub
Partager