Macro que cambia texto de los comentarios -celda vacía

Hola, tengo esta macro en la que tu me has colaborado.
Sub Macro7()
Dim MiComentario As Variant
Dim NUEVO As String
Dim TEXTO As String
On Error Resume Next
Set MiComentario = ActiveCell.Comment
If MiComentario Is Nothing Then
If ActiveCell.Comment = "" Then
NUEVO = (ActiveCell)
ActiveCell.AddComment.Text Text:=NUEVO
Else
End If
Else
TEXTO = ActiveCell.Comment.Text
NUEVO = ActiveCell
ActiveCell.Comment.Text Text:=""
ActiveCell.Comment.Text Text:=NUEVO
End If
End Sub

La macro funciona a la perfección salvo por un detalle, digamos que en la celda A1 tenia como valor "x" por lo tanto el comentario también quedo con el texto "x", si después de eso dejo la celda vacía permanece el valor "x" en el comentario. Me gustaría que quedara vacío el comentario al igual que la celda.
Muchas gracias

1 respuesta

Respuesta
1
prueba esto, inserta esta linea ActiveCell.Comment.Delete
entre las lineas
On Error Resume Next  y Set MiComentario = ActiveCell.Comment
quedando asi:
On Error Resume Next
ActiveCell.Comment.Delete
Set MiComentario = ActiveCell.Comment
Hola, tengo esta macro en la que tu me has colaborado.
Sub Macro7()
Dim MiComentario As Variant
Dim NUEVO As String
Dim TEXTO As String
On Error Resume Next
Set MiComentario = ActiveCell.Comment
If MiComentario Is Nothing Then
If ActiveCell.Comment = "" Then
NUEVO = (ActiveCell)
ActiveCell.AddComment.Text Text:=NUEVO
Else
End If
Else
TEXTO = ActiveCell.Comment.Text
NUEVO = ActiveCell
ActiveCell.Comment.Text Text:=""
ActiveCell.Comment.Text Text:=NUEVO
End If
End Sub

La macro funciona a la perfección salvo por un detalle, digamos que en la celda A1 tenia como valor "x" por lo tanto el comentario también quedo con el texto "x", si después de eso dejo la celda vacía permanece el valor "x" en el comentario. Me gustaría que quedara vacío el comentario al igual que la celda.
Muchas gracias

¿Y no hay la posibilidad de que solo quede vacío el texto del comentario? Sucede que al eliminarlo y volverlo a poner me borra el formato del comentario, ¿o se puede incluir el formato del comentario en la macro?
Ya lo solucioné!
inserte la línea ActiveCell.Comment.Text Text:="" & Chr(10) & ""
entre las lineas
On Error Resume Next  y Set MiComentario = ActiveCell.Comment
quedando asi:
On Error Resume Next
inserte la línea ActiveCell.Comment.Text Text:="" & Chr(10) & ""
Set MiComentario = ActiveCell.Comment
Muchas Gracias por tu ayuda!
Mmmm... prueba esto:
Dim MiComentario As Variant
Dim NUEVO As String
Dim TEXTO As String
On Error Resume Next
Set MiComentario = ActiveCell.Comment
If MiComentario Is Nothing Then
If ActiveCell.Comment = "" Then
NUEVO = (ActiveCell)
ActiveCell.AddComment.Text Text:=NUEVO
Else
End If
Else
TEXTO = ActiveCell.Comment.Text
NUEVO = ActiveCell
ActiveCell.Comment.Text Text:=""
If ActiveCell = Empty Then
NUEVO = " "
ActiveCell.Comment.Text Text:=NUEVO
Else
ActiveCell.Comment.Text Text:=NUEVO
End If
End If

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas