Error en una macro con comentario anidado
Hoy vengo a pedirle su ayuda, cuando ejecuto la macro no me da el resultado que deseo sino otra condicion en mi comentario. Ejemplo. Selecciono 10 o mas filas y ejecuto mi macro claro cada uno con con comentario como ven en la imagen pero lo que yo deseo es que por fila salga el comentario: aguas & "la fecha que sale en la primera columna de la fila" & "la hora que depende la segunda columna de la fila" y & la celda misma eso si me sale bien como ven en la foto tengo un problema en ello.
asi es como me sale LA CUAL ESTA MAL
Asi yo deseo que me obtenga LA CUAL ESTA BIEN
Claro la hora aumenta un par de segundos cada ves k pasa a otra columna pero toda la hora es referente de la segunda columna alguna ayuda por favor si tienen dudas puedo pasarles el archivo a su correo.
1
3
A = 1
For Each rngCell In Selection
If rngCell <> Empty Then
p = rngCell.Row
c = rngCell.Column
s = Range(primerabusqueda).Offset(p - I, 0).Value
r = Range(primerabusqueda).Offset(p - I, 1).Value
If rngCell.Comment Is Nothing Then
rngCell.AddComment
If IsDate(rngCell.Value) = True Then
rngCell.Comment.Text Text:="aguas " & s & " " & TimeValue(r) + TimeValue("0:00:10") & " " & Format(rngCell.Value, "yyyy-mm-dd")
ElseIf rngCell.Value = Range(primerabusqueda).Offset(p - I, 1).Value Then
rngCell.Comment.Text Text:="aguas " & s & " " & TimeValue(r) + TimeValue("0:00:10") & " " & Format(rngCell.Value, "hh:mm:ss AM/PM")
Else
rngCell.Comment.Text Text:="aguas " & s & " " & TimeValue(r) + TimeValue("0:00:10") & " " & rngCell.Value
End If
With rngCell
.Comment.Shape.Width = 120.64
.Comment.Shape.Height = 84.64
End With
A = A + 1
End If
End If
Next rngCell
On Error GoTo 0
ElseIf Not Selection.Find("día", , xlValues, xlWhole, xlByColumns, xlNext, False, , False) Is Nothing Then
Set resultado = Selection.Find("día", , xlValues, xlWhole, xlByColumns, xlNext, False, , False)
primerabusqueda = resultado.Address
Intersect(Selection, Selection. Offset(ActiveCell.Offset(1, 0). Row - ActiveCell. Row, 0)).Select
A = 1
For Each rngCell In Selection
If rngCell <> Empty Then
p = rngCell.Row
c = rngCell.Column
s = Range(primerabusqueda).Offset(p - I, 0).Value
H = Abs(4 * Sin(p - I) - 0.1 / (-Sin(6 / (-3.14159264 * (p - I) / 180))))
r = Application.WorksheetFunction.Text(Now() + 0.041666667 * H + c * 0.00001159 * (3 - 1 / A), "h:mm:ss AM/PM")
If rngCell.Comment Is Nothing Then
rngCell.AddComment
If IsDate(rngCell.Value) = True Then
rngCell.Comment.Text Text:="aguas " & s & " " & r & " " & Format(rngCell.Value, "yyyy-mm-dd")
Else
rngCell.Comment.Text Text:="aguas " & s & " " & r & " " & rngCell.Value
End If
With rngCell
.Comment.Shape.Width = 120.64
.Comment.Shape.Height = 84.64
End With
A = A + 1
End If
End If
Next rngCell
On Error GoTo 0
End If
Else
'realiza una nueva seleccion sin tomar en cuenta el encabezado de la tabla
Intersect(Selection, Selection. Offset(ActiveCell.Offset(1, 0). Row - ActiveCell. Row, 0)).Select
A = 1
For Each rngCell In Selection
If rngCell <> Empty Then
p = rngCell.Row
c = rngCell.Column
s = Range(primerabusqueda).Offset(p - I, 0).Value
H = Abs(4 * Sin(p - I) - 0.1 / (-Sin(6 / (-3.14159264 * (p - I) / 180))))
r = Application.WorksheetFunction.Text(Now() + 0.041666667 * H + c * 0.00001159 * (3 - 1 / A), "h:mm:ss AM/PM")
If rngCell.Comment Is Nothing Then
rngCell.AddComment
If IsDate(rngCell.Value) = True Then
rngCell.Comment.Text Text:="aguas " & s & " " & r & " " & Format(rngCell.Value, "yyyy-mm-dd")
Else
rngCell.Comment.Text Text:="aguas " & s & " " & r & " " & rngCell.Value
End If
With rngCell
.Comment.Shape.Width = 120.64
.Comment.Shape.Height = 84.64
End With
A = A + 1
End If
End If
Next rngCell
On Error GoTo 0
End If
End Sub
1 respuesta
Respuesta de Dante Amor
1








