Que faut-il modifier dans ce code ?

M

Mathieu

Guest
Bonsoir,

Je voudrais par un USF inscrire dans la feuille TOTO en K5 ce que je saisis dans la TextBox1. Tout fonctionne sauf qu' en K5, je ne vois rien. Dans le code je mets ceci:

Dim L As Integer
L = Range("K5")
If TextBox1 = " " Then
MsgBox "Vous n'avez rien saisi!"
TextBox1.SetFocus
Exit Sub
End If
Sheets("TOTO").Activate
With Sheets("TOTO")
.Range("K5" & L).Value = TextBox1.Value
End With
TextBox1.Value = " "
TextBox1.SetFocus
End Sub

Private Sub CommandButton2_Click()
Unload UserForm2
End Sub

Par quoi faut-il remplacer Dim L As Integer pour avoir le résultat en K5 ?

Merci.
 
M

Minick

Guest
Salut,

Comme ceci, L ne sert a rien dans ton code

.range("K5").value=TextBox1.value suffit à renseigner la cellule K5


If TextBox1 = "" Then
MsgBox "Vous n'avez rien saisi!"
TextBox1.SetFocus
Exit Sub
End If

With Sheets("TOTO")
.Range("K5").Value = TextBox1.Value
End With
TextBox1.Value = ""
TextBox1.SetFocus
End Sub

Private Sub CommandButton2_Click()
Unload UserForm2
End Sub


@+ Minick
 
M

Minick

Guest
Salut,

A la place de Exit Sub utilise un Else ca fait plus clean

If TextBox1 = "" Then
MsgBox "Vous n'avez rien saisi!"
TextBox1.SetFocus
else
With Sheets("TOTO")
.Range("K5").Value = TextBox1.Value
End With
TextBox1.Value = ""
TextBox1.SetFocus
End If
End Sub

@+ Minick
 
B

Bricofire

Guest
bonsoir,
vite fait pour la syntaxe...

Si L est une cellulle, il faudrait la déclarer en Variable Objet pour la manipuler comme telle, sinon tu affectes le contenu qui devra répondre au format "Integer"....

Soluce = Minick sinon surement

bonsoir à tous les deux,

Bfr
 

Discussions similaires

Réponses
1
Affichages
285
Réponses
12
Affichages
541

Statistiques des forums

Discussions
312 797
Messages
2 092 209
Membres
105 283
dernier inscrit
mcb33610