Jak
Well-known Member
- Joined
- Apr 5, 2002
- Messages
- 833
I have the following macro that swaps the cells value of adjoining cells in a row when highlighted. I need to be able swap cells contents in a column, i.e.
The current macro will change DAY GOOD to GOOD DAY when I highlight the ajoining cells and run the code on a row. I also need to be able to highlight adjoining cells in a column and perform the same cell transfer of data i.e.
DAY
GOOD
would become
GOOD
DAY
I hope this makes scense, any help appreciated.
The current macro will change DAY GOOD to GOOD DAY when I highlight the ajoining cells and run the code on a row. I also need to be able to highlight adjoining cells in a column and perform the same cell transfer of data i.e.
DAY
GOOD
would become
GOOD
DAY
I hope this makes scense, any help appreciated.
Code:
Option Explicit
Sub SwapContents()
Dim rng As Range
Dim tmp As String
For Each rng In Selection.Cells
If Not (Intersect(rng.Offset(, 1), Selection) Is Nothing) Then
tmp = rng.Formula
rng.Formula = rng.Offset(, 1).Formula
rng.Offset(, 1).Formula = tmp
End If
Next
End Sub