Un peut d'aide sur VBA

janick

XLDnaute Occasionnel
Bonjour,

Je souhaiterais démasquer une serie de colonne et ne masquer que celles qui seront vide et cela sur les douze feuilles (janvier/décembre) avec un bouton de commande qui change de couleur.
Voici mon bout de prog qui bien sure ne fonctionne pas.

Dim i As Integer
Dim col As Variant

Private Sub CommandButton3_Click()

If CommandButton3.Caption = "Masqué" Then
CommandButton3.BackColor = &HFF&
For i = 1 To Sheets.Count
Sheets(i). For col = 170 To 206
With Feuil1.Cells(64, col)
If .Value = "" Then Columns(col).Hidden = True
End With
Next col

Next i

CommandButton3.Caption = "DéMasqué"
CommandButton3.BackColor = &HC000&

Else
For i = 1 To Sheets.Count
Sheets(i). For col = 170 To 206
With Feuil1.Cells(64, col)
If .Value = "" Then Columns(col).Hidden = False
End With
Next col

Next i

CommandButton3.Caption = " Masqué "
CommandButton3.BackColor = &HFF&
End If
End Sub
 

youky(BJ)

XLDnaute Barbatruc
Re : Un peut d'aide sur VBA

Bonjour janick,
Essai ce code, aprés réflexion j'ai peut être inversé les couleurs.
Bruno
Code:
Private Sub CommandButton3_Click()
For i = 1 To Sheets.Count
 With Sheets(i)
    For col = 170 To 206
     Columns(col).Hidden = IIf(CommandButton3.Caption = "Masqué" And .Cells(64, col) = "", True, False)
    Next col
 End With
Next i
If CommandButton3.Caption = "Masqué" Then
CommandButton3.Caption = "DéMasqué"
 CommandButton3.BackColor = &HC000&
Else
CommandButton3.Caption = "Masqué"
 CommandButton3.BackColor = &HFF&
End If
End Sub
 

Papou-net

XLDnaute Barbatruc
Re : Un peut d'aide sur VBA

Bonjour janick,

Comme ceci peut-être ?

Dim i As Integer
Dim col As Variant

Code:
Private Sub CommandButton3_Click()

If CommandButton3.Caption = "Masqué" Then
   CommandButton3.Caption = "DéMasqué"
   CommandButton3.BackColor = &HC000&
  Else
   CommandButton3.Caption = " Masqué "
   CommandButton3.BackColor = &HFF&
End If
For i = 1 To Sheets.Count
   With Sheets(i)
      For col = 170 To 206
       Columns(col).Hidden = Iif(.Cells(64, col).Value = "", True, False)
             Next col
   End With
Next i
End Sub

Mais sans fichier, pas facile de savoir si ça répond à la question.

Cordialement.

Oups : Bonjour Youky, tu as été le plus rapide.

Cordialement.
 

janick

XLDnaute Occasionnel
Re : Un peut d'aide sur VBA

Bonjour,

Merci de vos réponses mai je n'arrive toujours pas au resultat espéré:
Dans le module j'utilise

Sub masquer1()
Dim col As Variant
For col = 170 To 206
With Feuil1.Cells(64, col)
If .Value = "" Then Columns(col).Hidden = True
End With
Next col
End Sub

Sub Afficher1()
Dim col As Variant
For col = 170 To 206
With Feuil1.Cells(64, col)
If .Value = "" Then Columns(col).Hidden = False
End With
Next col
End Sub

mais je souhaiterais pourvoir exécuter sur les douze mois cette double commande sur un seul bouton commande

Ci joint le bout de fichier

Merci de vos reflextions
 

Pièces jointes

  • _EVP_test.xls
    745.5 KB · Affichages: 53

janick

XLDnaute Occasionnel
Re : Un peut d'aide sur VBA

Bonjour,

je suis toujours perdu dans cette serie de commandes

Private Sub CommandButton4_Click()
Dim col As Variant
Dim i As Integer
Dim Ind As Integer, TabMois() As String, ShtS As Worksheet
If CommandButton4.Caption = "Masqué Col" Then
CommandButton4.BackColor = &HFF&
'selectionner les douze feuilles pour effectuer la même commande
TabMois = Split("Janvier,fevrier,mars,avril,mai,juin,juillet,aout,septembre,octobre,novembre,decembre", ",")
For Ind = 0 To UBound(TabMois)
Set ShtS = Sheets(TabMois(Ind))
Next
'démasquer les colones de 170 à 206 et masques que les colones vide ligne 64
For col = 170 To 206
With ActiveSheet.Cells(64, col)
Columns(col).Hidden = IIf(CommandButton3.Caption = "Masqué" And Columns(64, col) = "", True, False)
'If .Value = "" Then Columns(col).Hidden = True

' Next col
End With



CommandButton4.Caption = "Démasqué Col"
CommandButton4.BackColor = &HC000&
' For col = 170 To 206
' With ActiveSheet.Cells(64, col)
' If .Value = "" Then Columns(col).Hidden = False
' End With
Else
CommandButton4.Caption = "Masqué Col"
CommandButton4.BackColor = &HFF&
End If
End Sub
 

Discussions similaires

Réponses
11
Affichages
291

Statistiques des forums

Discussions
312 210
Messages
2 086 279
Membres
103 170
dernier inscrit
HASSEN@45