I have a spreadsheet that I use to track personel changes in my office. I use a macro that swaps information in 2 different cells that are selected. I would also like it to swap the cells comments when I use this macro. Can anyone modify this macro to do this?
Here is the macro -
Sub SwapSelections()
Dim rCell1 As Range
Dim rCell2 As Range
Dim strg1 As String, strg2 As String
If Selection.Cells.Count > 2 Or Selection.Cells.Count < 2 Then
MsgBox "Your selection should only contain 2 cells", vbCritical
End
End If
If Selection.Areas.Count > 1 Then
Set rCell1 = Selection.Areas(1).Cells(1, 1)
Set rCell2 = Selection.Areas(2).Cells(1, 1)
ElseIf Selection.Rows.Count > Selection.Columns.Count Then
Set rCell1 = Selection.Range("A1")
Set rCell2 = Selection.Range("A2")
Else
Set rCell1 = Selection.Range("A1")
Set rCell2 = Selection.Range("B1")
End If
With rCell1
strg1 = .Value
inCl1 = .Interior.Color
End With
With rCell2
strg2 = .Value
inCl2 = .Interior.Color
End With
With rCell1
.Value = strg2
.Interior.Color = inCl2
End With
With rCell2
.Value = strg1
.Interior.Color = inCl1
End With
End Sub
----------------------------------------------------------
Thanks!
Here is the macro -
Sub SwapSelections()
Dim rCell1 As Range
Dim rCell2 As Range
Dim strg1 As String, strg2 As String
If Selection.Cells.Count > 2 Or Selection.Cells.Count < 2 Then
MsgBox "Your selection should only contain 2 cells", vbCritical
End
End If
If Selection.Areas.Count > 1 Then
Set rCell1 = Selection.Areas(1).Cells(1, 1)
Set rCell2 = Selection.Areas(2).Cells(1, 1)
ElseIf Selection.Rows.Count > Selection.Columns.Count Then
Set rCell1 = Selection.Range("A1")
Set rCell2 = Selection.Range("A2")
Else
Set rCell1 = Selection.Range("A1")
Set rCell2 = Selection.Range("B1")
End If
With rCell1
strg1 = .Value
inCl1 = .Interior.Color
End With
With rCell2
strg2 = .Value
inCl2 = .Interior.Color
End With
With rCell1
.Value = strg2
.Interior.Color = inCl2
End With
With rCell2
.Value = strg1
.Interior.Color = inCl1
End With
End Sub
----------------------------------------------------------
Thanks!