Recherche avec Boucle

kalenjiman

XLDnaute Nouveau
Bonjour,

Après avoir essayer des heures durant je me résigne a vous demander un coup de main.

J’ai une macro qui me permet de chercher le mot « Total » dans la colonne D. Je souhaiterais la peaufiner un peu, afin que :

• Si la valeur de la cellule a droite du mot « Total » est différente de zero j’active la cellule F de cette même ligne
• Si la valeur est égale à zero, je recherche le prochain mot « Total »

Ci-dessous ma macro:

PHP:
Sub Search_Total3()
'Selectionne la cellule "Remise" dans une ligne contenant le mot "Total"

Dim Lg As Long

Lg = ActiveCell.Row
Set Total = Range("D" & Lg & ":D1510").Find("Total", LookIn:=xlValues, lookat:=xlWhole)
If Total Is Nothing Then Exit Sub

        If Cells(Total.Row, 5) <> 0 Then
            Cells(Total.Row, 6).Select
        Else

?????????????
?????????????

End If
End Sub
 

Pièces jointes

  • Total Search.xlsm
    13.5 KB · Affichages: 49

Modeste

XLDnaute Barbatruc
Re : Recherche avec Boucle

Bonsoir kalenjiman,

A tester ... si j'ai bien compris ...
VB:
Sub Search_Total()
'Selectionne la cellule "Remise" dans une ligne contenant le mot "Total"

Dim Lg As Long
Dim Total As Range

Set Total = Range("D:D").Find("Total", LookIn:=xlValues, lookat:=xlWhole)
    If Total Is Nothing Then Exit Sub
    prem = Total.Address
    Do
        If Total.Offset(0, 1).Value <> 0 Then
            Total.Offset(0, 2).Activate
            Exit Sub
        End If
        Set Total = Range("D:D").FindNext(Total)
    Loop While Not Total Is Nothing And Total.Address <> prem
End Sub
 

kalenjiman

XLDnaute Nouveau
Re : Recherche avec Boucle

Merci Modeste, après une legere modification ça marche parfaitement.

Code:
Sub SearchTotal()

Dim Lg As Long
Dim Total As Range

Lg = ActiveCell.Row
Set Total = Range("D" & Lg & ":D1510").Find("Total", LookIn:=xlValues, lookat:=xlWhole)
    If Total Is Nothing Then Exit Sub
    Prem = Total.Address
    Do
        If Total.Offset(0, 1).Value <> 0 Then
            Total.Offset(0, 2).Activate
            Exit Sub
        End If
        Set Total = Range("D:D").FindNext(Total)
    Loop While Not Total Is Nothing And Total.Address <> Prem
End Sub
 

Statistiques des forums

Discussions
312 231
Messages
2 086 447
Membres
103 213
dernier inscrit
Poupoule