Hi all,
Just need some quick help with a couple of codes I have working almost perfectly.
I need comments to stack or add to any comment already in the target cell.
I have tried removing the line of code .ClearComments without any luck. I get a 400 error upon running it.
Any ideas on a solution?
Many thanks in advance.
Just need some quick help with a couple of codes I have working almost perfectly.
I need comments to stack or add to any comment already in the target cell.
I have tried removing the line of code .ClearComments without any luck. I get a 400 error upon running it.
Any ideas on a solution?
Many thanks in advance.
VBA Code:
Sub swaptosameplace()
Dim sCmt As String
Dim i As Long
Dim rCell As Range
Dim area1 As Variant, area2 As Variant, swapval As Variant
sCmt = InputBox( _
Prompt:="Enter details of the swap. Including when it was actioned and by who." & vbCrLf & _
"Comment will be added to all cells in Selection", _
Title:="DAO Swap Details")
If sCmt = "" Then
MsgBox "No comment added"
Else
For Each rCell In Selection
With rCell
.ClearComments
.AddComment
.Comment.Text Text:=sCmt
End With
Next
End If
Set rCell = Nothing
If Selection.Areas.Count <> 2 Then Exit Sub
If Selection.Areas(1).Columns.Count <> Selection.Areas(2).Columns.Count Then
MsgBox ("Selection areas must have the same number of columns")
Exit Sub
End If
area1 = Selection.Areas(1)
area2 = Selection.Areas(2)
If Selection.Areas(1).Columns.Count = 1 Then
swapval = area1
area1 = area2
area2 = swapval
Else
For i = LBound(area1, 2) To UBound(area1, 2)
swapval = area1(1, i)
area1(1, i) = area2(1, i)
area2(1, i) = swapval
Next
End If
Selection.Areas(1) = area1
Selection.Areas(2) = area2
End Sub