liste déroulante

roisabri

XLDnaute Nouveau
Salut Mes amis,

Voilà mes 2 problèmes :

Ce bout de code marche bien.

Code:
LastRow = Worksheets(Data).Range("B" & Rows.Count).End(xlUp).row

With Worksheets(Plans).Range(Cells(3, 3).Address & ":" & Cells(Rows.Count, 3).End(xlUp).Address).Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=Data!$B$2:$B$" & LastRow
        .ErrorMessage = "You don't have the persmissison to write"
    End With

1-Le problème :
Formula1:="=Data!$B$2:$B$" & LastRow ==>cette ligne de code je n'arrive pas à le faire marcher d'une autre manière.

Je veux que =====> Formula1:="Alpha;Gamma;Beta" avec

Const Alpha=1
Const Gamma="Go"
Const Beta="Now"

Quand je fais ce code, il affiche une liste n'es pas déroulante et un seul choix qui est Alpha;Gamma;Beta cad il ne voit les valeurs des variables

2- problème :Je veux que lors de l'affichage de la liste , j'attribue couleur rouge pour Gamma et vert pour Beta.


Merci d'avance
 

Pierrot93

XLDnaute Barbatruc
Re : liste déroulante

Re,

avec une MFC :
Code:
With Range(Cells(3, 3).Address & ":" & Cells(Rows.Count, 3).End(xlUp).Address)
    With .Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:="Alpha,Gamma,Beta"
        .ErrorMessage = "You don't have the persmissison to write"
    End With
    With .FormatConditions
        .Delete
        .Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="=""Alpha"""
        .Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="=""Gamma"""
        .Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="=""Beta"""
    End With
    .FormatConditions(1).Interior.ColorIndex = 3
    .FormatConditions(2).Interior.ColorIndex = 4
    .FormatConditions(3).Interior.ColorIndex = 45
End With
 

roisabri

XLDnaute Nouveau
Re : liste déroulante

Merci beaucoup Philippe vraiment tu es géniale,

Là il reste un problème,

Il n'arrive pas à trouver les valeurs des variables Alpha Beta Gamma

J'ai bien vérifié que ses variables sont publics , je ne vois pas où est il le problème ? :)

Merci
 

Pierrot93

XLDnaute Barbatruc
Re : liste déroulante

Re,

Il n'arrive pas à trouver les valeurs des variables Alpha Beta Gamma

bah... en l'état du code proposé, ne va pas rechercher des valeurs de variables... si c'est le cas :
Code:
Dim var1, var2, var3
var1 = "xxx": var2 = "yyy": var3 = "zzz"
With Range(Cells(3, 3).Address & ":" & Cells(Rows.Count, 3).End(xlUp).Address)
    With .Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:=var1 & "," & var2 & "," & var3
        .ErrorMessage = "You don't have the persmissison to write"
    End With
    With .FormatConditions
        .Delete
        .Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="=""Alpha"""
        .Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="=""Gamma"""
        .Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="=""Beta"""
    End With
    .FormatConditions(1).Interior.ColorIndex = 3
    .FormatConditions(2).Interior.ColorIndex = 4
    .FormatConditions(3).Interior.ColorIndex = 45
End With
 

Pierrot93

XLDnaute Barbatruc
Re : liste déroulante

Re,

pour les MFC :
Code:
         .Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="=""" & var1 & """"
        .Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="=""" & var2 & """"
        .Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="=""" & var3 & """"
 

roisabri

XLDnaute Nouveau
Re : liste déroulante

Rebonjour mes amis,

Je reviens sur cette discussion vu que j'ai un nouveau besoin ...

En réalité cette liste sera mis à jour à avant chaque utilisation
Code:
 Set Cell_Color = Worksheets(Data).Range("P2")
    While Not Cell_Color.Interior.Color = Gray Or Cell_Color.Interior.Color = White
        i = i + 1
        Set Cell_Color = Cell_Color.offset(1, 0)
    Wend
    
    
    With Worksheets(Plans).Range(Cells(3, 15).Address & ":" & Cells(Rows.Count, 15).End(xlUp).Address).Validation
            .Delete
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:="=Data!$B$2:$B$" & i
            .ErrorMessage = "You don't have the persmissison to write"
        End With
        With .FormatConditions
                .Delete
                For j = 2 To i
                .Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="=""B"" & i & """""
                Next
            End With
            
        For j = 1 To i - 1
        .FormatConditions(j).Interior.Color = Sheets(Data).Cells(j, 16).Interior.Color
        Next
        
    End With

Le code marche, mais il ne fait aucun modification de couleur sur la cellule!! des solutions?
 

Discussions similaires

Statistiques des forums

Discussions
312 792
Messages
2 092 143
Membres
105 235
dernier inscrit
loisipubm