Microsoft 365 Variable non définie

Usine à gaz

XLDnaute Barbatruc
Supporter XLD
Bonjour à toutes et à tous,
Je vous souhaite une belle journée :)

Je n'arrive pas à faire fonctionner cette ch'tite boucle ... nul je suis
Et je ne comprends pas pourquoi :mad:

Je me permets de vous vous soumettre mon code (qui est dans ma feuille) :
VB:
Option Explicit
'CreateObject("wscript.shell").SendKeys "{F2}"
'CreateObject("wscript.shell").SendKeys "{ESC}"
'CreateObject("wscript.shell").SendKeys "% ~{UP 30}{LEFT 20}~"
Private Sub Worksheet_Activate()
    If Sheets("Table").Range("n4") = "ouvert" Then
    Application.EnableEvents = False
    Application.ScreenUpdating = False
    Sheets("Table").Select
    Application.EnableEvents = True
    Application.ScreenUpdating = True
    MsgBox ("L'affectation doit être terminée" & Chr(10) & "avant tout autre action" & Chr(10) & Chr(10) & "clic sur cellule ICI" & Chr(10) & "pour affecter votre appel")
    Exit Sub
    End If
   
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    ActiveWindow.LargeScroll ToRight:=-1
    ActiveSheet.Unprotect Password:=""
    Range(Cells(1, 14), Cells(1, 1)).Select
    ActiveWindow.Zoom = True 'ActiveWindow.Zoom = 114
    [A5] = "=""Eblts     ""&""       clic = Tri"""
    ActiveWindow.DisplayHorizontalScrollBar = False
    Range([a6], Cells(Rows.Count, "a").End(xlUp)).RowHeight = 55
   
    Columns("N:N").Select
    With Selection.Font
        .Color = -16777024
        .TintAndShade = 0
    End With
   
'    For i = 6 To 10000
'        If Cells(i, 10) = "NPR" Then
'        Rows.RowHeight = 55
'        End If
'    Next i

'    For i = 6 To Range("J" & Rows.Count).End(xlUp).Row
'        If Cells(i, 10) = "NPR" Then
'        Rows.RowHeight = 0
'        End If
'    Next

    [c1].Select
    ActiveSheet.Protect Password:="", DrawingObjects:=True, Contents:=True, Scenarios:=True
     Application.ScreenUpdating = True
    Application.EnableEvents = True
End Sub
et la photo du beugue :
1636542555836.png

Pourriez-vous m'aider ?

Mille remerciements,
lionel :)
 
Dernière édition:
Solution
C
Salut Lionel,

Il suffit d'ajouter un test 😜
VB:
For i = 6 To Range("J" & Rows.Count).End(xlUp).Row
    If Cells(i, 10) = "NPR" or Cells(i, 10) = "RdV Fait" then Rows(i).Hidden = True
Next i

A+

Jacky67

XLDnaute Barbatruc
Bonjour à toutes et à tous,
Je vous souhaite une belle journée :)

Je n'arrive pas à faire fonctionner cette ch'tite boucle ... nul je suis
Et je ne comprends pas pourquoi :mad:

Je me permets de vous vous soumettre mon code (qui est dans ma feuille) :
VB:
Option Explicit
'CreateObject("wscript.shell").SendKeys "{F2}"
'CreateObject("wscript.shell").SendKeys "{ESC}"
'CreateObject("wscript.shell").SendKeys "% ~{UP 30}{LEFT 20}~"
Private Sub Worksheet_Activate()
    If Sheets("Table").Range("n4") = "ouvert" Then
    Application.EnableEvents = False
    Application.ScreenUpdating = False
    Sheets("Table").Select
    Application.EnableEvents = True
    Application.ScreenUpdating = True
    MsgBox ("L'affectation doit être terminée" & Chr(10) & "avant tout autre action" & Chr(10) & Chr(10) & "clic sur cellule ICI" & Chr(10) & "pour affecter votre appel")
    Exit Sub
    End If
 
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    ActiveWindow.LargeScroll ToRight:=-1
    ActiveSheet.Unprotect Password:=""
    Range(Cells(1, 14), Cells(1, 1)).Select
    ActiveWindow.Zoom = True 'ActiveWindow.Zoom = 114
    [A5] = "=""Eblts     ""&""       clic = Tri"""
    ActiveWindow.DisplayHorizontalScrollBar = False
    Range([a6], Cells(Rows.Count, "a").End(xlUp)).RowHeight = 55
 
    Columns("N:N").Select
    With Selection.Font
        .Color = -16777024
        .TintAndShade = 0
    End With
 
'    For i = 6 To 10000
'        If Cells(i, 10) = "NPR" Then
'        Rows.RowHeight = 55
'        End If
'    Next i

'    For i = 6 To Range("J" & Rows.Count).End(xlUp).Row
'        If Cells(i, 10) = "NPR" Then
'        Rows.RowHeight = 0
'        End If
'    Next

    [c1].Select
    ActiveSheet.Protect Password:="", DrawingObjects:=True, Contents:=True, Scenarios:=True
     Application.ScreenUpdating = True
    Application.EnableEvents = True
End Sub
et la photo du beugue :
Regarde la pièce jointe 1121001
Pourriez-vous m'aider ?

Mille remerciements,
lionel :)
Bonjour à tous
En plus des instructions déjà données
Attention à la boucle.....
"Rows.RowHeight = 0" affecte toute la feuille
Si cela doit être la colonne J contenant "NPR"
Alors
Rows(i).RowHeight...
ou
Rows(i).Hidden = True
Selon.......
 
Dernière édition:

Efgé

XLDnaute Barbatruc
Re
Pour suivre Jacky67
Je dirais même plus, avec
VB:
For i = 6 To Range("J" & Rows.Count).End(xlUp).Row
    Rows(i).Hidden = Cells(i, 10) = "NPR"
Next i
On peux surement supprimer la boucle précédente
Code:
 For i = 6 To Range("J" & Rows.Count).End(xlUp).Row
        If Cells(i, 10) = "NPR" Then
        Rows.RowHeight = 55
        End If
    Next

Cordialement
 
Dernière édition:

Usine à gaz

XLDnaute Barbatruc
Supporter XLD
Bonjour Jacky67, Efgé, le Forum,
Bon WE à toutes et à tous :)

Pourriez-vous encore m'aider pour ce code que vous m'avez donné ?
VB:
    For i = 6 To Range("J" & Rows.Count).End(xlUp).Row
    Rows(i).Hidden = Cells(i, 10) = "NPR"
    Next i
Je voudrais que les lignes soient "Hidden" dans les deux cas "NPR" et "RdV Fait"
Je ne sais pas le coder.

je vous remercie par avance,
Amicalement,
lionel,
 

Efgé

XLDnaute Barbatruc
Bonjour à tous
Je pense, mais peut-être me trompe-je que la propostion de BrunoM45 , que je salut, n'affiche pas les lignes qui ne comporteraient pas "RDV fail" ou "NPR"
Je propose
VB:
For i = 6 To Range("J" & Rows.Count).End(xlUp).Row
    Rows(i).Hidden = (Cells(i, 10) ="NPR" or Cells(i, 10) = "RdV Fait")
Next i

Non testé sur le fichier mais a verifier quand même...

Après on peut voir
Code:
For i = 6 To Range("J" & Rows.Count).End(xlUp).Row
    If Cells(i, 10) = "NPR" or Cells(i, 10) = "RdV Fait" then 
           Rows(i).Hidden = True
    Else
                     Rows(i).Hidden = False
   End IF
Next i

Cordialement
 

Discussions similaires

Réponses
8
Affichages
447