Swaping cell values

Jak

Well-known Member
Joined
Apr 5, 2002
Messages
796
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.


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
 

Jak

Well-known Member
Joined
Apr 5, 2002
Messages
796
Many thanks for the quick response Glenn. Works a treat, cheers.
 

Forum statistics

Threads
1,078,068
Messages
5,338,018
Members
399,195
Latest member
cmdv

Some videos you may like

This Week's Hot Topics

Top