Ajouter un commentaire avec texte saisi dans une textbox
lauresk
Messages postés2Date d'inscriptionmardi 9 février 2010StatutMembreDernière intervention12 mars 2010
-
12 mars 2010 à 15:28
lauresk
Messages postés2Date d'inscriptionmardi 9 février 2010StatutMembreDernière intervention12 mars 2010
-
12 mars 2010 à 20:01
Bonjour,
je cherche à attribuer un commentaire à une cellule excel.
Le texte de ce commentaire est récupéré dans une textbox au sein d'une userform. Et pour compliquer le tout, ayant 69 textbox je souhaite que l' ajout des 69 commentaires dans les 69 cellules se fasse dans une boucle.
j'ai la procédure suivante qui bloque et ne trouve pas la solution. Quelqu'un pour m'aider ?
i = 1
Do While i < 70
With Worksheets(strWSName)
txtcomment = UserForm4.Controls("TextBox" & i).Text
j = 133 + i
c = i + 2
.Cells(c, colonne).Value = UserForm4.Controls("ComboBox" & j).Value
.Cells(c, colonne).Select
"message erreur à la ligne suivante : Run Time error 1004"
.Cells(c, colonne).AddComment
.Cells(c, colonne).Comment.Visible = False
.Cells(c, colonne).Comment Text:="" & txtcomment
Select Case UserForm4.Controls("ComboBox" & i).Text
Case "Avaria"
.Cells(c, colonne).Interior.ColorIndex = cor1
Case ("Manutenção Preventiva")
.Cells(c, colonne).Interior.ColorIndex = cor2
Case ("Preventiva Semestral")
.Cells(c, colonne).Interior.ColorIndex = cor3
Case ("Funcionando com restrições")
.Cells(c, colonne).Interior.ColorIndex = cor4
Case ("Funcionando subutilizada")
.Cells(c, colonne).Interior.ColorIndex = cor5
Case ("Funcionando Integralmente")
.Cells(c, colonne).Interior.ColorIndex = cor6
Case ("")
.Cells(c, colonne).Interior.ColorIndex = cor6
End Select
i = i + 1
End With
cnt
Messages postés219Date d'inscriptionlundi 21 novembre 2005StatutMembreDernière intervention20 décembre 20101 12 mars 2010 à 19:40
Salut
je pense qu'il doit y avoir déjà un commentaire dans la cellule. Faut donc effacer celui-ci
.Cells(c, colonne).Comment.Delete
.Cells(c, colonne).AddComment Text:="" & txtcomment
ou plus simplement
.Cells(c, colonne).Comment.Text txtcomment
lauresk
Messages postés2Date d'inscriptionmardi 9 février 2010StatutMembreDernière intervention12 mars 2010 12 mars 2010 à 20:01
CNTJC,
Merci pour ta réponse rapide.
Je viens de tester et c'est une nouvelle erreur :
Run-Time error "91"
object variable or with block variable not set
au niveau de la ligne :
.Cells(c, colonne).Comment.Delete
je copies ma sub ici, il y a peut-être une déclaration que je n'ai pas faite correctement...
Private Sub CommandButton1_Click()
Dim strWSName As String
Dim txtcomment As String
Dim mois As Integer
Dim jour As Integer
Dim colonne As Integer
mois = month(UserForm4.tbxdata.Value)
jour = Day(UserForm4.tbxdata.Value)
colonne = jour + 3
' recuperation du nom du mois pour selection de la feuille
With Worksheets("Data")
strWSName = .Cells(mois, 2).Value
i = 1
Do While i < 70
With Worksheets(strWSName)
txtcomment = UserForm4.Controls("TextBox" & i).Text
j = 133 + i
c = i + 2
.Cells(c, colonne).Value = UserForm4.Controls("ComboBox" & j).Value
.Cells(c, colonne).Comment.Delete
.Cells(c, colonne).Select
.Cells(c, colonne).AddComment
.Cells(c, colonne).Comment.Visible = False
.Cells(c, colonne).Comment.Delete
Select Case UserForm4.Controls("ComboBox" & i).Text
Case "Avaria"
.Cells(c, colonne).Interior.ColorIndex = cor1
Case ("Manutenção Preventiva")
.Cells(c, colonne).Interior.ColorIndex = cor2
Case ("Preventiva Semestral")
.Cells(c, colonne).Interior.ColorIndex = cor3
Case ("Funcionando com restrições")
.Cells(c, colonne).Interior.ColorIndex = cor4
Case ("Funcionando subutilizada")
.Cells(c, colonne).Interior.ColorIndex = cor5
Case ("Funcionando Integralmente")
.Cells(c, colonne).Interior.ColorIndex = cor6
Case ("")
.Cells(c, colonne).Interior.ColorIndex = cor6
End Select
i = i + 1
End With