Valider automatiquement Inputbox VBA
O
Bonjour,
Je débute en VBA et je souhaite créer un bouton me permettant de remplacer une mise en forme conditionnelle sur les cellules sélectionnées par une nouvelle couleur de fond.
J'ai réussi en combinant deux codes trouver sur le net : le premier pour supprimer la MFC, le deuxième changer la couleur de fond des cellules.
Cela fonctionne mais j'ai une demande de validation de la plage sélectionnée à chaque manip qui m'ennuie.
Après des recherches sur le net j'ai vu le code :
Application.DisplayAlerts = False
et
SendKeys("{ENTER}")
Mais je ne parviens à faire marcher aucun d'eux pour retirer cette pop up (j'ai essayé de l'insérer entre chacun ligne de code une à une au cas où ^^).
Voici le code VBA brut :
Sub changement()
Dim xRg As Range
Dim xTxt As String
Dim xCell As Range
On Error Resume Next
If ActiveWindow.RangeSelection.Count > 1 Then
xTxt = ActiveWindow.RangeSelection.AddressLocal
Else
xTxt = ActiveSheet.UsedRange.AddressLocal
End If
Set xRg = Application.InputBox("", "", xTxt, , , , , 8)
If xRg Is Nothing Then Exit Sub
For Each xCell In xRg
With xCell
.Font.FontStyle = .DisplayFormat.Font.FontStyle
.Font.Strikethrough = .DisplayFormat.Font.Strikethrough
.Interior.Pattern = .DisplayFormat.Interior.Pattern
If .Interior.Pattern <> xlNone Then
.Interior.PatternColorIndex = .DisplayFormat.Interior.PatternColorIndex
.Interior.Color = .DisplayFormat.Interior.Color
End If
.Interior.TintAndShade = .DisplayFormat.Interior.TintAndShade
.Interior.PatternTintAndShade = .DisplayFormat.Interior.PatternTintAndShade
End With
Next
xRg.FormatConditions.Delete
'Colorer le fond des cellules sélectionnées
Selection.Interior.ColorIndex = 42
End Sub
Merci d'avance et bonne soirée !
Bonjour OncleSid,
Je te propose de modifier le code par :
Sub changement()
Dim xRg As Range
Dim xTxt As String
Dim xCell As Range
On Error Resume Next
If ActiveWindow.RangeSelection.Count > 1 Then
Set xRg = ActiveWindow.RangeSelection
Else
Set xRg = ActiveSheet.UsedRange
End If
'Set xRg = Application.InputBox("", "", xTxt, , , , , 8)
If xRg Is Nothing Then Exit Sub
For Each xCell In xRg
With xCell
.Font.FontStyle = .DisplayFormat.Font.FontStyle
.Font.Strikethrough = .DisplayFormat.Font.Strikethrough
.Interior.Pattern = .DisplayFormat.Interior.Pattern
If .Interior.Pattern <> xlNone Then
.Interior.PatternColorIndex = .DisplayFormat.Interior.PatternColorIndex
.Interior.Color = .DisplayFormat.Interior.Color
End If
.Interior.TintAndShade = .DisplayFormat.Interior.TintAndShade
.Interior.PatternTintAndShade = .DisplayFormat.Interior.PatternTintAndShade
End With
Next
xRg.FormatConditions.Delete
'Colorer le fond des cellules sélectionnées
Selection.Interior.ColorIndex = 42
End Sub