Insertion commentaires par userform

  • Initiateur de la discussion Initiateur de la discussion dj dim
  • Date de début Date de début

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 !

Re : Insertion commentaires par userform

Bonjour

Merci pour votre réponse.

J'ai tenté d'intégréer votre code dans mon userform mais cela ne fonctionne pas : "erreur 9 : indice n'appartenant pas à la selection "

Code:
Option Compare Text 'POUR IGNORER DIFFERENCE MAJUSCULES / MINUSCULES


Private ligne As Integer


'------ Ecriture des champs renseignés dans la Boite de Dialogue sur l'onglet Facturation ------'

Private Sub BoutonValider_Click()
ActiveSheet.Unprotect Password:="dt"
    
If Me.TextBox1.Value <> "" Then
ActiveSheet.Cells(ligne, Me.ComboBox1.ListIndex * 3 + 10).Value = CDec(Format(Me.TextBox1.Value, "0.0000"))
End If
If Me.TextBox2.Value <> "" Then
ActiveSheet.Cells(ligne, Me.ComboBox1.ListIndex * 3 + 11).Value = CDec(Format(Me.TextBox2.Value, "0.0000"))
End If
If Me.TextBox3.Value <> "" Then
ActiveSheet.Cells(ligne, Me.ComboBox1.ListIndex * 3 + 12).Value = CDec(Format(Me.TextBox3.Value, "0.0000"))
End If
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="dt"
  On Error Resume Next
  With ActiveSheet.Cells(ligne, Me.ComboBox1.ListIndex * 3 + 12)
   .AddComment
   On Error GoTo 0
   .Comment.Text Text:=Replace(Me.TextBox4, Chr(13), "")
   .Comment.Visible = True
   .Comment.Shape.Select
   Selection.AutoSize = True
   .Comment.Visible = False
  End With
  Unload Me
End Sub


'----------- Mise en forme et recherche des infos du ComboBox1 -------------'

Private Sub UserForm_Initialize()
For i = 1 To 12 ' CHARGEMENT DES MOIS DANS UNE ANNEE, ET MISE EN MAJUSCULES
ComboBox1.AddItem Format(Format("1/" & i, "mmmm"), ">")

Next i
ComboBox1.Value = Format(Format(CDate(Date), "mmmm"), ">")

 With Me.ListView1
             .Gridlines = True
             .View = 3
             .MultiSelect = True
             .FullRowSelect = True

                     With .ColumnHeaders
                          .Add , , "N° COMPTE", 60
                          .Add , , "AGENCE", 80, lvwColumnCenter
                          .Add , , "CLIENT", 185
                     End With
End With

Worksheets("Facturation").Activate

With Me.ListView1

  For j = 6 To ActiveSheet.Range("A65536").End(xlUp).Row
      .ListItems.Add , , ActiveSheet.Cells(j, 1).Value 'N° DE COMPTE
      .ListItems(.ListItems.Count).ListSubItems.Add , , ActiveSheet.Cells(j, 2).Value ' AGENCE
      .ListItems(.ListItems.Count).ListSubItems.Add , , ActiveSheet.Cells(j, 3).Value ' NON CLIENT


Next j
End With

For Each FEUILLE In ThisWorkbook.Worksheets
    If FEUILLE.Name = ComboBox1.Value Then FEUILLE.Activate
Next

ligne = 6

Me.TextBox1.Text = ActiveSheet.Cells(ligne, 1).Value
Me.TextBox2.Text = ActiveSheet.Cells(ligne, 2).Value
Me.TextBox3.Text = ActiveSheet.Cells(ligne, 3).Value

Me.Label4.Caption = Me.ComboBox1.Value & " - " & Me.ListView1.ListItems(1).Text & " - " _
& Me.ListView1.ListItems(1).ListSubItems(1).Text & " - " & Me.ListView1.ListItems(1).ListSubItems(2).Text

End Sub


'----------- Mise en forme et recherche des infos de la ListView1 -------------'

Private Sub ListView1_Click()

Dim c As Range
With ActiveSheet.Range("A6:A500")
Set c = .Find(Me.ListView1.SelectedItem, LookIn:=xlValues)
If Not c Is Nothing Then ligne = c.Row
End With
With Sheets("Commercial").Range("A5:A500")
Set c = .Find(Me.ListView1.SelectedItem, LookIn:=xlValues)
If Not c Is Nothing Then Me.TextBox4 = c.Offset(0, 10)
Select Case c.Offset(0, 10).Value
Case ""
Me.TextBox4.BackColor = RGB(255, 255, 255)
Case "Pieds de Facture"
Me.TextBox4.BackColor = RGB(151, 255, 255) 'cyan'
Case "Facture Complémentaire"
Me.TextBox4.BackColor = RGB(255, 105, 180) 'rose'
Case "Sur les Tarifs"
Me.TextBox4.BackColor = RGB(0, 255, 0) 'vert fluo'
End Select
End With



Me.TextBox1.Value = Cells(ligne, Me.ComboBox1.ListIndex * 3 + 10).Value
Me.TextBox2.Value = Cells(ligne, Me.ComboBox1.ListIndex * 3 + 11).Value
Me.TextBox3.Value = Cells(ligne, Me.ComboBox1.ListIndex * 3 + 12).Value

Me.Label4.Caption = Me.ListView1.SelectedItem.Text & " - " _
& Me.ListView1.SelectedItem.ListSubItems(1).Text & " - " & Me.ListView1.SelectedItem.ListSubItems(2).Text

TextBox1.Value = Format(TextBox1.Value, "# ,##0.00 [-40C]")
TextBox2.Value = Format(TextBox2.Value, "0.00%")
TextBox3.Value = Format(TextBox3.Value, "# ,##0.00 [-40C]")

If ActiveCell.Comment Is Nothing Then
    Facturation.TextBox4 = Now & Chr(10) & Environ("username") & Chr(10)
  Else
    Facturation.TextBox4 = ActiveSheet.Cells(ligne, Me.ComboBox1.ListIndex * 3 + 12).Comment.Text
  End If
End Sub


' ------ Tri lors de la sélection d'une colonne ----------'

Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
    ListView1.Sorted = False
    ListView1.SortKey = ColumnHeader.Index - 1
    
    If ListView1.SortOrder = lvwAscending Then
        ListView1.SortOrder = lvwDescending
        Else
        ListView1.SortOrder = lvwAscending
    End If
    
    ListView1.Sorted = True
End Sub


'--------- Remplace les . par des , dans la TextBox1 ---------'

Private Sub TextBox1_Change()
TextBox1 = Replace(TextBox1.Value, ".", ",")
End Sub


'--------- Remplace les . par des , dans la TextBox2 ---------'

Private Sub TextBox2_Change()
TextBox2 = Replace(TextBox2.Value, ".", ",")
End Sub


'--------- Remplace les . par des , dans la TextBox3 ---------'

Private Sub TextBox3_Change()
TextBox3 = Replace(TextBox3.Value, ".", ",")
End Sub


'---------- Multiplication dans la TextBox3 ------------'

Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
        On Error Resume Next ' Si ce n'est pas une saisie conforme!
        TextBox3 = TextBox1 * TextBox2 / 100
 
        TextBox2.Value = Format(TextBox2.Value / 100, "0.00%")
        TextBox1.Value = Format(TextBox1.Value, "# ,##0.00 [-40C]")
        TextBox3.Value = Format(TextBox3.Value, "# ,##0.00 [-40C]")
End Sub
 
Re : Insertion commentaires par userform

Bonjour à tous,

Je me permets de vous solliciter à nouveau car j'ai inseré dans mon précédent userform une TextBox (TextBox5) me permettant d'inserer des commentaires dans la case qui recevra la valeur de la TextBox4.

Malheureusement mon code ne fonctionne pas et je ne vois pas où cela cloche : "erreur de compilation : argument non facultatif"

Voici le code :

Code:
Option Compare Text 'POUR IGNORER DIFFERENCE MAJUSCULES / MINUSCULES


Private ligne As Integer


'------ Ecriture des champs renseignés dans la Boite de Dialogue sur l'onglet Facturation ------'

Private Sub BoutonValider_Click()
ActiveSheet.Unprotect Password:="dt"
    
If Me.TextBox1.Value <> "" Then
ActiveSheet.Cells(ligne, Me.ComboBox1.ListIndex * 3 + 10).Value = CDec(Format(Me.TextBox1.Value, "0.0000"))
End If
If Me.TextBox2.Value <> "" Then
ActiveSheet.Cells(ligne, Me.ComboBox1.ListIndex * 3 + 11).Value = CDec(Format(Me.TextBox2.Value, "0.0000"))
End If
If Me.TextBox3.Value <> "" Then
ActiveSheet.Cells(ligne, Me.ComboBox1.ListIndex * 3 + 12).Value = CDec(Format(Me.TextBox3.Value, "0.0000"))
End If
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="dt"
  On Error Resume Next
  With ActiveSheet.Cells(ligne, Me.ComboBox1.ListIndex * 3 + 12)
   .AddComment
   On Error GoTo 0
   .Comment.Text Text:=Replace(Me.TextBox5, "")
   .Comment.Visible = True
   .Comment.Shape.Select
   Selection.AutoSize = True
   .Comment.Visible = False
  End With
  Unload Me
End Sub


'----------- Mise en forme et recherche des infos du ComboBox1 -------------'

Private Sub UserForm_Initialize()
For i = 1 To 12 ' CHARGEMENT DES MOIS DANS UNE ANNEE, ET MISE EN MAJUSCULES
ComboBox1.AddItem Format(Format("1/" & i, "mmmm"), ">")

Next i
ComboBox1.Value = Format(Format(CDate(Date), "mmmm"), ">")

 With Me.ListView1
             .Gridlines = True
             .View = 3
             .MultiSelect = True
             .FullRowSelect = True

                     With .ColumnHeaders
                          .Add , , "N° COMPTE", 60
                          .Add , , "AGENCE", 80, lvwColumnCenter
                          .Add , , "CLIENT", 185
                     End With
End With

Worksheets("Facturation").Activate

With Me.ListView1

  For j = 6 To ActiveSheet.Range("A65536").End(xlUp).Row
      .ListItems.Add , , ActiveSheet.Cells(j, 1).Value 'N° DE COMPTE
      .ListItems(.ListItems.Count).ListSubItems.Add , , ActiveSheet.Cells(j, 2).Value ' AGENCE
      .ListItems(.ListItems.Count).ListSubItems.Add , , ActiveSheet.Cells(j, 3).Value ' NON CLIENT


Next j
End With

For Each FEUILLE In ThisWorkbook.Worksheets
    If FEUILLE.Name = ComboBox1.Value Then FEUILLE.Activate
Next

ligne = 6

Me.TextBox1.Text = ActiveSheet.Cells(ligne, 1).Value
Me.TextBox2.Text = ActiveSheet.Cells(ligne, 2).Value
Me.TextBox3.Text = ActiveSheet.Cells(ligne, 3).Value

Me.Label4.Caption = Me.ComboBox1.Value & " - " & Me.ListView1.ListItems(1).Text & " - " _
& Me.ListView1.ListItems(1).ListSubItems(1).Text & " - " & Me.ListView1.ListItems(1).ListSubItems(2).Text

End Sub


'----------- Mise en forme et recherche des infos de la ListView1 -------------'

Private Sub ListView1_Click()

Dim c As Range
With ActiveSheet.Range("A6:A500")
Set c = .Find(Me.ListView1.SelectedItem, LookIn:=xlValues)
If Not c Is Nothing Then ligne = c.Row
End With
With Sheets("Commercial").Range("A5:A500")
Set c = .Find(Me.ListView1.SelectedItem, LookIn:=xlValues)
If Not c Is Nothing Then Me.TextBox4 = c.Offset(0, 10)
Select Case c.Offset(0, 10).Value
Case ""
Me.TextBox4.BackColor = RGB(255, 255, 255)
Case "Pieds de Facture"
Me.TextBox4.BackColor = RGB(151, 255, 255) 'cyan'
Case "Facture Complémentaire"
Me.TextBox4.BackColor = RGB(255, 105, 180) 'rose'
Case "Sur les Tarifs"
Me.TextBox4.BackColor = RGB(0, 255, 0) 'vert fluo'
End Select
End With



Me.TextBox1.Value = Cells(ligne, Me.ComboBox1.ListIndex * 3 + 10).Value
Me.TextBox2.Value = Cells(ligne, Me.ComboBox1.ListIndex * 3 + 11).Value
Me.TextBox3.Value = Cells(ligne, Me.ComboBox1.ListIndex * 3 + 12).Value

Me.Label4.Caption = Me.ListView1.SelectedItem.Text & " - " _
& Me.ListView1.SelectedItem.ListSubItems(1).Text & " - " & Me.ListView1.SelectedItem.ListSubItems(2).Text

TextBox1.Value = Format(TextBox1.Value, "# ,##0.00 [-40C]")
TextBox2.Value = Format(TextBox2.Value, "0.00%")
TextBox3.Value = Format(TextBox3.Value, "# ,##0.00 [-40C]")

If ActiveCell.Comment Is Nothing Then
    Facturation.TextBox5 = Environ("username") & Chr(13)
  Else
    Facturation.TextBox5 = ActiveSheet.Cells(ligne, Me.ComboBox1.ListIndex * 3 + 12).Comment.Text
  End If
End Sub


' ------ Tri lors de la sélection d'une colonne ----------'

Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
    ListView1.Sorted = False
    ListView1.SortKey = ColumnHeader.Index - 1
    
    If ListView1.SortOrder = lvwAscending Then
        ListView1.SortOrder = lvwDescending
        Else
        ListView1.SortOrder = lvwAscending
    End If
    
    ListView1.Sorted = True
End Sub


'--------- Remplace les . par des , dans la TextBox1 ---------'

Private Sub TextBox1_Change()
TextBox1 = Replace(TextBox1.Value, ".", ",")
End Sub


'--------- Remplace les . par des , dans la TextBox2 ---------'

Private Sub TextBox2_Change()
TextBox2 = Replace(TextBox2.Value, ".", ",")
End Sub


'--------- Remplace les . par des , dans la TextBox3 ---------'

Private Sub TextBox3_Change()
TextBox3 = Replace(TextBox3.Value, ".", ",")
End Sub


'---------- Multiplication dans la TextBox3 ------------'

Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
        On Error Resume Next ' Si ce n'est pas une saisie conforme!
        TextBox3 = TextBox1 * TextBox2 / 100
 
        TextBox2.Value = Format(TextBox2.Value / 100, "0.00%")
        TextBox1.Value = Format(TextBox1.Value, "# ,##0.00 [-40C]")
        TextBox3.Value = Format(TextBox3.Value, "# ,##0.00 [-40C]")
End Sub
 
Dernière édition:
Re : Insertion commentaires par userform

J'ai troouvé ce code mais je n'arrive pas à le modifier de manière à saisir via une TextBox situé dans un usf (de saisie et consultation) et pouvoir également consulter via cette même TextBox


Code:
Private Sub CommandButton5_Click() 
Dim strresponse As String, strprompt As String, strtitle As String 
strresponse = "" 
strprompt = "Veuillez taper votre commentaire" 
strtitle = "Commentaire" 
strresponse = InputBox(strprompt, strtitle, strresponse) 
 
   Sheets("BD_Compteur" ).Select 
   Range("E4" ).Select 
   Application.DisplayCommentIndicator = xlCommentIndicatorOnly 
   Range("E4" ).AddComment 
   Range("E4" ).Comment.Visible = False 
   Range("E4" ).Comment.Text Text:=strresponse & Chr(10) & "" & Chr(10) & "" 
   Range("E5" ).Select 
 
End Sub
 
- 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

Réponses
2
Affichages
187
  • Question Question
Réponses
28
Affichages
509
Retour