Saltar al contenido

Insertar Comentario en celda desde textbox de un userform

publicado

Buen día, tengo el siguiente problema:

Necesito insertar un comentario en una celda de un registro de datos que se va completando a través de un Userform. Uso el siguiente código (En rojo, las líneas que insertan el comentario en la celda):

 Set TransRowRng = ThisWorkbook.Worksheets("RESUMEN GENERAL").Cells(1, 1).CurrentRegion
        NewRow = TransRowRng.Rows.Count + 1
                            
        With ThisWorkbook.Worksheets("RESUMEN GENERAL")
          
           .Cells(NewRow, 1) = CDate(txtFechaUno)
           .Cells(NewRow, 2) = UCase(TextBox1.Value)
           .Cells(NewRow, 3) = Format(TextBox3, "00"".""000"".""000""-""0")
           .Cells(NewRow, 4) = ComboBox1
           .Cells(NewRow, 5) = CDbl(TextBox2)
           .Cells(NewRow, 5).AddComment
           .Cells(NewRow, 5).Comment.Text Text:=TextBox6.Value

           .Cells(NewRow, 6) = UCase(TextBox5)
           .Cells(NewRow, 7) = ComboBox2
           .Cells(NewRow, 8) = Val(TextBox4)
                If .Cells(NewRow, 8).Value = 0 Then
                    .Cells(NewRow, 8).Select
                    Selection.ClearContents
                End If
        Sheets("RESUMEN GENERAL").Select
        Range("a1").End(xlDown).Select
        End With

El problema que se me presenta es cuando dejo vacío el TextBox6 (porque no siempre necesito insertar comentarios en esa celda); me manda a depurar.. Me edad error.

Que puedo hacer para eliminar este error?

 

 

Featured Replies

publicado
  • Autor

Además me gustaría que cuando el TextBox6 quede vacío, no inserte comentarios en esa celda.

publicado
if Not Trim(TextBox6) = "" Then
   .Cells(NewRow, 5).AddComment
   .Cells(NewRow, 5).Comment.Text Text:=TextBox6
End If

 

publicado
  • Autor

Muchas Gracias Antoni.   Estaba cerca de la solución...   Pero siempre es bueno consultar con los expertos.

Gracias....

Archivado

Este tema está ahora archivado y está cerrado a más respuestas.