Simplification de code

Bonjour,

J'essaye de me débrouiller en code, j'en tenter un truc et j'aurai avoir vos retours si la façon de faire, j'ai comme l'impression que c'est un peu lourd tout ça

Application.ScreenUpdating = False

Set F1 = Worksheets("repart")

With F1
Set Plage = .Range("N3:N59")

End With

For Z = 3 To 29 Step 1

For Each cell In Plage

cell.Select
If cell.Value = Cells(Z, 3).Value Then Selection.Interior.Color = F1.Cells(Z, 3).Interior.Color
If cell.Value = Cells(Z, 3).Value Then Selection.Font.Color = F1.Cells(Z, 3).Font.Color

cell.Select
If cell.Value = Cells(Z, 5).Value Then Selection.Interior.Color = F1.Cells(Z, 5).Interior.Color
If cell.Value = Cells(Z, 5).Value Then Selection.Font.Color = F1.Cells(Z, 5).Font.Color

cell.Select
If cell.Value = Cells(Z, 7).Value Then Selection.Interior.Color = F1.Cells(Z, 7).Interior.Color
If cell.Value = Cells(Z, 7).Value Then Selection.Font.Color = F1.Cells(Z, 7).Font.Color

cell.Select
If cell.Value = Cells(Z, 9).Value Then Selection.Interior.Color = F1.Cells(Z, 9).Interior.Color
If cell.Value = Cells(Z, 9).Value Then Selection.Font.Color = F1.Cells(Z, 9).Font.Color

Next

Next Z

Application.ScreenUpdating = True

End Sub

J'ai tenté de simplifier surtout les cell.Select mais la macro fonctionne plus par la suite

Si vous pouvez me dire comment vous faites pour simplifier un code

Merci pour votre aide

Bonsoir,

Merci de joindre le fichier.

Salut Shenzar, Salut Raja,

à tester:

Application.ScreenUpdating = False

Set F1 = Worksheets("repart")

With F1
Set Plage = .Range("N3:N59")

End With

For Z = 3 To 29 Step 1

    For Each cell In Plage

        For Y = 3 To 9 Step 2
        cell.Select
        If cell.Value = Cells(Z, Y).Value Then
        Selection.Interior.Color = F1.Cells(Z, Y).Interior.Color
        Selection.Font.Color = F1.Cells(Z, Y).Font.Color
        Next Y

    Next

Next Z

Application.ScreenUpdating = True

End Sub

Bonne soirée

Bonjour Raja et M3ellem1,

Voici le fichier en question c'est un fichier test,

J'ai testé ton code, il ne fonctionne pas ^^

5to-do-v11.xlsm (182.33 Ko)

Sorry End if manquait

Sub Trouver_repart()
Application.ScreenUpdating = False

Set F1 = Worksheets("repart")

With F1
Set Plage = .Range("N3:N69")

End With

For Z = 3 To 29 Step 1

    For Each cell In Plage

        For Y = 3 To 9 Step 2
        cell.Select
        If cell.Value = Cells(Z, Y).Value Then
        Selection.Interior.Color = F1.Cells(Z, Y).Interior.Color
        Selection.Font.Color = F1.Cells(Z, Y).Font.Color
        End If
        Next Y
    Next
Next Z

Application.ScreenUpdating = True
End Sub

Ton code fonctionne bien

J'ai du mal avec les x, y, z pourtant j'en ai mangé en bts m'enfin

Donc tu mets que y en abscisse c'est ça ?

Le temps de chargement et quasi similaire, si j'ai 3000 lignes sa va être chaud, pour le moment 69 lignes semble pas ralentir la machine

pour mieux comprendre il faut utiliser i et j

i ==> le Nr. de la ligne

j ==> le Nr. de la colonne

Sub Trouver_repart()
Dim i As Integer, j As Integer
Application.ScreenUpdating = False

Set F1 = Worksheets("repart")

With F1
Set Plage = .Range("N3:N69")

End With

For i = 3 To 29 Step 1

    For Each cell In Plage

        For j = 3 To 9 Step 2
        cell.Select
        If cell.Value = Cells(i, j).Value Then
        Selection.Interior.Color = F1.Cells(i, j).Interior.Color
        Selection.Font.Color = F1.Cells(i, j).Font.Color
        End If
        Next j
    Next
Next i

Application.ScreenUpdating = True
End Sub

pour le temps de chargement, on desactive le ScreenUpdating et si c'est lent, il faut voir comment optimiser le code.

Bonne journée

Je comprends un peu mieux, mais sa va rentrer faut du temps

Merci pour ton aide en tout cas

Rechercher des sujets similaires à "simplification code"