Remplacer "GoTo" dans VBA

Bonjour à toutes et à tous,

J'aimerais savoir si quelqu'un pourrait m'aider à remplacer "GoTo" dans ma macro spv

Voici le code :

Sub aa()

Dim i As Integer, j As Integer

Application.ScreenUpdating = False

For i = 2 To Range("A1048576").End(xlUp).Row

With Application.Workbooks("Antoine 2.xlsx").Sheets("Feuil1")

For j = 2 To .Range("C1048576").End(xlUp).Row

If Cells(i, 1) = .Cells(j, 3) And Cells(i, 2) = .Cells(j, 4) Then

Range(Cells(i, 1), Cells(i, 2)).Font.ColorIndex = 4 ' vert

GoTo Etiquette

End If

Next j

Range(Cells(i, 1), Cells(i, 2)).Font.ColorIndex = 3 ' rouge

Etiquette:

End With

Next i

End Sub

Cordialement Antoine

Bonjour,

Tu peux essayer un truc comme ça :

Sub aa()
Dim i As Integer, j As Integer
Application.ScreenUpdating = False
With Application.Workbooks("Antoine 2.xlsx").Sheets("Feuil1")
ii = Range("A1048576").End(xlUp).Row
jj = .Range("C1048576").End(xlUp).Row
   For i = 2 To ii
   k = 3 ' rouge
   j = 2
      Do Until k = 4 Or j = jj
         If Cells(i, 1) = .Cells(j, 3) And Cells(i, 2) = .Cells(j, 4) Then k = 4 ' vert
      j = j + 1
      Loop
    Range(Cells(i, 1), Cells(i, 2)).Font.ColorIndex = k
    Next i
End With
End Sub

A+

Bonjour,

J'ai pas tout suivi sue ta macro, mais essais ceci :

Sub aa()
 Dim i As Integer, j As Integer, k as Integer

 Application.ScreenUpdating = False

 For i = 2 To Range("A1048576").End(xlUp).Row
    With Application.Workbooks("Antoine 2.xlsx").Sheets("Feuil1")
    k = 0
    For j = 2 To .Range("C1048576").End(xlUp).Row
       If Cells(i, 1) = .Cells(j, 3) And Cells(i, 2) = .Cells(j, 4) Then
          Range(Cells(i, 1), Cells(i, 2)).Font.ColorIndex = 4 ' vert
          k = k+1
       End If
    Next j
    If k = 0 then
       Range(Cells(i, 1), Cells(i, 2)).Font.ColorIndex = 3 ' rouge
    End if
    End With
 Next i

 End Sub

Cordialement,

Je vous remercie tout d'abords tous les 2 de m'avoir envoyer ces codes Zirak ton code est bon sa va me permettre d'avancer cette après midi par contre Galopin01 t'a une erreur sur cette ligne là : "ii = Range("A1048576").End(xlUp).Row"

Probablement par ce que tu as mis un option Explicit...

DAns ce cas il suffit de modifier les déclarations de la manière suivante :

Sub aa()
 Dim i%, j%, k%, ii%, jj%

'le reste sans changement...

Re !!

Pensez-vous pouvoir me faire une boucle mais avec While ?

Svp

Bonjour,

Dans la macro précédente il fallait corriger :

jj = .Range("C1048576").End(xlUp).Row + 1

sinon la dernière ligne n'est pas examinée...

pour une boucle While (C'est un exercice d'école ?) :

Sub aa()
Dim i%, j%, k%, ii%, jj%
Application.ScreenUpdating = False
With Application.Workbooks("Antoine 2.xlsx").Sheets("Feuil1")
ii = Range("A1048576").End(xlUp).Row + 1
jj = .Range("C1048576").End(xlUp).Row + 1
i = 2
   While i < ii
   k = 3 ' rouge
   j = 2
      Do Until k = 4 Or j = jj
         If Cells(i, 1) = .Cells(j, 3) And Cells(i, 2) = .Cells(j, 4) Then k = 4 ' vert
      j = j + 1
      Loop
    Range(Cells(i, 1), Cells(i, 2)).Font.ColorIndex = k
    i = i + 1
    Wend
End With
End Sub

A+

Rechercher des sujets similaires à "remplacer goto vba"