Changer Couleur TextBox et enregistrer ds feuille

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

Provence Vintage

XLDnaute Occasionnel
Bonjour Le Forum,

Je cherche à ecrire un code pour

1) changer couleur en rouge de la TextBox si option cliqué par exemple avec un optionbutton

couleur normale Noire si "non"!

2) j'enregistre mes valeurs de TextBox dans une feuille, que dois-je rajouter à mon code pour qu'il prenne en compte également la variable couleur

3) dans un autre USF je consulte mes données enregistrées dans une feuille via des TextBox, comment puis-je faire pour récupérer mes données enregistrées en couleur rouge donc tenir compte de la variable couleur!

PS/ celà s'applique pour 8 TextBox, et 8 colonnes

Merci d'avance
 
Re : Changer Couleur TextBox et enregistrer ds feuille

Le Fil,

Désolé d'insister, mais je ne trouve pas de Tuto sur les codes concernant les couleurs pour ce que je veux faire, à savoir comment copier la valeur et la couleur d'un textbox dans une feuille????
merci d'avance au + réactif
 
Re : Changer Couleur TextBox et enregistrer ds feuille

Bonsoir à Tout le forum.
Patience Provence Vintage.

Je ne suis pas expert alors j'e tai "bricolé" un bout d'essai joint en pJ.
Je suis parti de la correspondance des couleurs issue de la "Palette Excel"
trouvée sur ce forum via "recherche" au chapitre "Correspondance couleurs"
Ce n'est surement pas la panacée d'autant qu'il te faudra adapter à tes besoins pour les couleurs et cellules de destination.

A+
Daniel
 

Pièces jointes

Re : Changer Couleur TextBox et enregistrer ds feuille

Mfb, Le Fil;


Déjà, sympa de t'être intéressé au sujet....!

Malgré ce que tu m'as donné a manger, malheureusement, celà reste du chinois....

Ok pour la correspondance des couleurs, le vrai soucis, c que j'ai capté le code pour lui dire change moi la couleur dans une Textbox, en fonction d'une Check, d'un texte saisi ou autre, mais quid, quand on veux copier et la valeur de la Text et sa couleur dans une feuille....

if u please....
 
Re : Changer Couleur TextBox et enregistrer ds feuille

Bonsoir le fil, bonsoir le forum

Peut-être comme ça :
Code:
Private Sub CommandButton1_Click()
With Cells(3, 3)
    .Value = ComboBox1.Value
    .Interior.Color = Me.ComboBox1.BackColor
End With
Cells(1, 1).Select
End Sub
 
Re : Changer Couleur TextBox et enregistrer ds feuille

Bonsoir le fil, bonsoir le forum,

Je comprends rien a ton dernier code. La propriété ForeColor n'existe pas pour un Range ! J'avoue ne pas avoir compris vraiment ton problème. Dans un premier temps tu parles d'un OptionButton et d'une TextBox puis dans ton exemple tu affiches une ComboBox... Fais un effort si tu veux qu'on en fasse pour toi !!!
À mon avis ta solution est dans le Interior.Color et non pas dans le Interior.ColorIndex mais je me demande si tu prends le temps de lire les réponses...
 
Re : Changer Couleur TextBox et enregistrer ds feuille

Carcharodon Carcharias, Robert, Le Fil,

Dans mon USF,
J'ai 8 Combo avec Un CheckBox qui me permet lorsque clické de changer la couleur de l'écriture via le code:


Private Sub CheckBox15_Click()
If CheckBox15 = True Then
ComboBox1.ForeColor = &HC0&
ComboBox2.ForeColor = &HC0&
ComboBox3.ForeColor = &HC0&
ComboBox4.ForeColor = &HC0&
ComboBox5.ForeColor = &HC0&
ComboBox6.ForeColor = &HC0&
ComboBox7.ForeColor = &HC0&
ComboBox8.ForeColor = &HC0&
Else
If CheckBox15 = False Then
ComboBox1.ForeColor = &H80000008
ComboBox2.ForeColor = &H80000008
ComboBox3.ForeColor = &H80000008
ComboBox4.ForeColor = &H80000008
ComboBox5.ForeColor = &H80000008
ComboBox6.ForeColor = &H80000008
ComboBox7.ForeColor = &H80000008
ComboBox8.ForeColor = &H80000008
End If
End If
End Sub

Si Clické, en Rouge, sinon, en Noir,

Ensuite, Mon Command me permet de copier toutes les combo et TextBox dans une base de données par colonne, via le code suivant:


Private Sub CommandButton1_Click()
Application.ScreenUpdating = False


Sheets("Base de Données acheteurs").Activate
Dim NomDeFeuilEnCours$, lidep1 As Long, cellule As Range
NomDeFeuilEnCours = "Base de Données acheteurs"
Dim Ctrl As Control
Dim Valeur As String
Dim Vr As Byte, Fx As Byte
For Each Ctrl In Me.Controls
If TypeOf Ctrl Is MSForms.CheckBox Then
If Ctrl.Value = True Then
Valeur = Valeur & Ctrl.Name & " = True " & Chr(10)
Vr = Vr + 1
Else
Valeur = Valeur & Ctrl.Name & " =False " & Chr(10)
Fx = Fx + 1
If CréerFicheAcquéreur.TextBox9.Value = "" Then
MsgBox " Le Nom de l'acquéreur est obligatoire . "
Exit Sub
End If
End If
End If
Next


li = Range("A6000").End(xlUp).Row
li = li + IIf(li < 4, 2, 1) ' à cause des lignes fusionnées !
Cells(li, 1) = TextBox9.Value
Cells(li, 2) = TextBox10.Value
Cells(li, 2) = TextBox10.Value
Cells(li, 3) = TextBox5.Value
Cells(li, 4) = TextBox24.Value
Cells(li, 5) = TextBox25.Value
Cells(li, 6) = TextBox22.Value
Cells(li, 7) = IIf(OptionButton15, "Tous secteurs", "")
Cells(li, 8) = ComboBox1.Value
Cells(li, 9) = ComboBox2.Value
Cells(li, 10) = ComboBox3.Value
Cells(li, 11) = ComboBox4.Value
Cells(li, 12) = ComboBox5.Value
Cells(li, 13) = ComboBox6.Value
Cells(li, 14) = ComboBox7.Value
Cells(li, 15) = ComboBox8.Value
Cells(li, 16) = IIf(CheckBox1, "MDV", "") & IIf(CheckBox2, "Appart", "") & IIf(CheckBox3, "Villa", "") & IIf(CheckBox4, "Mas", "") & IIf(CheckBox5, "Terrain", "")
Cells(li, 17) = TextBox2.Value
Cells(li, 18) = IIf(CheckBox11, "Oui", "")
Cells(li, 19) = TextBox3.Value
Cells(li, 20) = TextBox4.Value
Cells(li, 21) = IIf(OptionButton1, "Oui", "")
Cells(li, 22) = IIf(OptionButton2, "Oui", "")
Cells(li, 23) = TextBox7.Value
Cells(li, 24) = TextBox8.Value
Cells(li, 25) = IIf(CheckBox6, "Oui", "")
Cells(li, 26) = IIf(CheckBox7, "Oui", "")
Cells(li, 27) = IIf(CheckBox8, "Oui", "")
Cells(li, 28) = IIf(CheckBox9, "Oui", "")
Cells(li, 29) = IIf(OptionButton11, "Cuisine US", "")
Cells(li, 29) = IIf(OptionButton10, "Cuisine séparée", "")
Cells(li, 30) = IIf(CheckBox10, "Oui", "")
Cells(li, 31) = TextBox20.Value
Cells(li, 32) = TextBox21.Value
Cells(li, 33) = IIf(CheckBox12, "Oui", "")
Cells(li, 34) = IIf(CheckBox13, "Oui", "")
Cells(li, 35) = TextBox23.Value
Cells(li, 36) = IIf(CheckBox14, "Oui", "")
Cells(li, 37) = TextBox19.Value

End With


Call trierzonedetriacheteurs
Call calculnombrefichesacheteurs
Unload Me


Application.ScreenUpdating = True
SaisirPije.Hide
Accueil.Show
CréerFicheAcquéreur.Hide
Accueil.Show
End Sub


Ma difficulté est de traduire dans ce dernier code non seulement le .Value, qui fonctionne bien, mais pour les 8 Combo, la couleur de l'écriture.....
J'ai bien testé ce que tu m'as proposé, mais sans succès.

Voulez vous un fichier exemple ou arrive tu à mieux cerner ma demande!
en tout cas merci à vous tous pour votre aide.
Bonne nuit si ce n'est déjà le cas ou à tte sur le Fil
 
Re : Changer Couleur TextBox et enregistrer ds feuille

bonsoir à tous

Code:
Private Sub CheckBox15_Click()
Dim Coul&
CoulRouge = 3: CoulNoir = 1
PalRouge& = &HC0&: PalNoir& = &H80000008
If CheckBox15 = True Then Coul& = PalRouge& Else Coul& = PalNoir&
ComboBox1.ForeColor = Coul&: ComboBox2.ForeColor = Coul&
ComboBox3.ForeColor = Coul&: ComboBox4.ForeColor = Coul&
ComboBox5.ForeColor = Coul&: ComboBox6.ForeColor = Coul&
ComboBox7.ForeColor = Coul&: ComboBox8.ForeColor = Coul&

'-------------------------------------------------------
'  SELON TON EXEMPLE TU ADAPTES ......
If ComboBox1.ForeColor = PalNoir& Then C = CoulNoir Else C = CoulRouge
Cells(li, 8).Value = ComboBox1.Value
Cells(li, 8).Font.ColorIndex = C
'-------------------------------------------------------
End Sub
 
Dernière édition:
Re : Changer Couleur TextBox et enregistrer ds feuille

Roland, carcharodon, Robert, Le Fil,

Merci, ça marche nickel,

Pour ma dernière opération concernant cette discussion,
il s'agit maintenant pour moi de récupérer les valeurs et couleurs enrengistrées dans une feuille via un USF"consultation",
Dans lequel j'ai glissé le code suivant:
(ça marche nickel pour les valeurs, par contre, tjrs pas pour récupérer les couleurs de mes cellules)



Dim cel As Range
Dim Coul&
CoulRouge = 3: CoulNoir = 1
PalRouge& = &HC0&: PalNoir& = &H80000008

If TextBox23 = "" Then
MsgBox " Le Nom de l'acheteur est obligatoire . "
Exit Sub
Else
Label44.Caption = "Recherche de " & TextBox23

Worksheets("Base de Données acheteurs").Activate
Set cel = Range("A1")
Set cel = Columns(1).Find(What:=TextBox23, After:=cel, _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If Not cel Is Nothing Then
L = cel.Row
If cel.Row.ForeColor = PalNoir& Then c = CoulNoir Else c = CoulRouge

Label45.Caption = "éxiste déjà " & L
TextBox24 = Cells(L, "B")
TextBox25 = Cells(L, "C")
TextBox26 = Cells(L, "D")
TextBox27 = Cells(L, "E")
TextBox28 = Cells(L, "F")
TextBox29 = Cells(L, "G")
TextBox30 = Cells(L, "H").Font.ColorIndex = c
TextBox31 = Cells(L, "I").Font.ColorIndex = c
TextBox32 = Cells(L, "J").Font.ColorIndex = c
TextBox33 = Cells(L, "K").Font.ColorIndex = c
TextBox34 = Cells(L, "L").Font.ColorIndex = c
TextBox35 = Cells(L, "M").Font.ColorIndex = c
TextBox36 = Cells(L, "N").Font.ColorIndex = c
TextBox37 = Cells(L, "O").Font.ColorIndex = c
TextBox38 = Cells(L, "P")
TextBox39 = Cells(L, "Q")
TextBox40 = Cells(L, "R")
TextBox41 = Cells(L, "S")
TextBox42 = Cells(L, "T")
TextBox43 = Cells(L, "U")
TextBox44 = Cells(L, "V")
TextBox45 = Cells(L, "W")
TextBox46 = Cells(L, "X")
TextBox47 = Cells(L, "Y")
TextBox48 = Cells(L, "Z")
TextBox49 = Cells(L, "AA")
TextBox50 = Cells(L, "AB")
TextBox51 = Cells(L, "AC")
TextBox52 = Cells(L, "AD")
TextBox53 = Cells(L, "AE")
TextBox54 = Cells(L, "AF")
TextBox55 = Cells(L, "AG")
TextBox56 = Cells(L, "AH")
TextBox57 = Cells(L, "AI")
TextBox58 = Cells(L, "AJ")
TextBox59 = Cells(L, "AK")
Sheets("ImprimFicheAcheteur").Range("B8") = TextBox23
Sheets("ImprimFicheAcheteur").Range("F8") = Cells(L, "C")
Sheets("ImprimFicheAcheteur").Range("F13") = Cells(L, "G")
Sheets("ImprimFicheAcheteur").Range("C11") = Cells(L, "P")
Sheets("ImprimFicheAcheteur").Range("B1") = Cells(L, "Q")
Sheets("ImprimFicheAcheteur").Range("C24") = Cells(L, "W")
Sheets("ImprimFicheAcheteur").Range("C26") = Cells(L, "U")
Sheets("ImprimFicheAcheteur").Range("C25") = Cells(L, "S")
Sheets("ImprimFicheAcheteur").Range("C27") = Cells(L, "T")
Sheets("ImprimFicheAcheteur").Range("C28") = Cells(L, "V")
Sheets("ImprimFicheAcheteur").Range("C29") = Cells(L, "Y")
Sheets("ImprimFicheAcheteur").Range("C30") = Cells(L, "AJ")
Sheets("ImprimFicheAcheteur").Range("B13") = Cells(L, "H")
Sheets("ImprimFicheAcheteur").Range("B14") = Cells(L, "I")
Sheets("ImprimFicheAcheteur").Range("B15") = Cells(L, "J")
Sheets("ImprimFicheAcheteur").Range("B16") = Cells(L, "K")
Sheets("ImprimFicheAcheteur").Range("B17") = Cells(L, "L")
Sheets("ImprimFicheAcheteur").Range("B18") = Cells(L, "M")
Sheets("ImprimFicheAcheteur").Range("B19") = Cells(L, "N")
Sheets("ImprimFicheAcheteur").Range("B20") = Cells(L, "O").Font.ColorIndex = c
Sheets("ImprimFicheAcheteur").Range("F2") = Cells(L, "AI")
Sheets("ImprimFicheAcheteur").Range("F1") = Cells(L, "F")
Sheets("ImprimFicheAcheteur").Range("C3") = Cells(L, "R")
Sheets("ImprimFicheAcheteur").Range("C4") = Cells(L, "AG")
Sheets("ImprimFicheAcheteur").Range("C5") = Cells(L, "AE")
Sheets("ImprimFicheAcheteur").Range("C6") = Cells(L, "AF")
Sheets("ImprimFicheAcheteur").Range("A32") = Cells(L, "AK")
Else
MsgBox "Pas trouvé"
TextBox23 = ""
TextBox23.SetFocus
End If
'End With
End If


TextBox23 = ""

End Sub


Merci à Tous
 
Re : Changer Couleur TextBox et enregistrer ds feuille

Le Fil, que ça puisse servir aux autres, j'ai trouvé;

Lorsqu'on a un usf et que l'on veux enregistrer via cet usf les valeurs et formats, couleurs des TextBos ou Combo.... dans une feuille et éventuellement re-consulter ces données via un autre usf; pour la couleur d'une cellule enregistrée dans une feuille, à récupérer via un TextBox ou Combo se fait via ce type de code:
With Me.TextBox30
.BackColor = Cells(L, "H").Interior.Color
.ForeColor = Cells(L, "H").Font.Color
End With
A+ sur le Forum
 
Re : Changer Couleur TextBox et enregistrer ds feuille

Bonjour le Fil,


je galère avec ce code pour copier la couleur du TextBox dans feuille et pouvoir la récupérer à consultation de l'USF!

#With Sheets("bdd acheteurs")
.Cells(b, 1) = LblRef
.Cells(b, 2) = CDate(Tbx2)
For i = 3 To 10
.Cells(b, i) = Controls("Tbx" & i)
Next
For i = 11 To 14
.Cells(b, i) = IIf(Controls("Cbx" & i), "X", "")
Next
.Cells(b, 15) = IIf(CbxNbMois, "Début", Tbx15)
For i = 16 To 20
.Cells(b, i) = IIf(Controls("Cbx" & i), "X", "")
Next
.Cells(b, 21) = Tbx21
.Cells(b, 22) = Cbo22
.Cells(b, 23) = Tbx23
.Cells(b, 24) = Cbo24
.Cells(b, 24).Fore.Color = Cbo24.Font.ColorIndex#

Merci par avance à celles et ceux qui peuvent m'aider....
Bonne fin de journée!
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

H
Réponses
3
Affichages
1 K
helencompta
H
M
Réponses
13
Affichages
2 K
D
Réponses
2
Affichages
2 K
deeppurple
D
J
Réponses
6
Affichages
2 K
mohand06
M
Retour