Swap pasting - cutting and pasting cells' contents

funguy

New Member
Joined
Feb 7, 2012
Messages
24
I'm doing a ton of corrections for mixed up information. Is there a function that will cut and paste a cell's contents and automatically push the destination's cells contents to the original cell that you cut from? i.e. - Swapping contents...

if that does exists, I'd assume I could assign a custom keyboard shortcut to the task. Any ideas would be great . thanks !
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
This is a very nice idea and very handy:)

Insert a Module and copy the below code to its code window.

You can then assign shortcut keys to SourceCell and DestinationCell.
Code:
[FONT="Consolas"][SIZE="2"][COLOR="Navy"]Option Explicit

Sub SourceCell()
    ActiveWorkbook.Names.Add Name:="SourceCell", RefersTo:="=" & ActiveCell.Address
End Sub

Sub DestinationCell_Swap()

    Dim vSwap As Variant

    vSwap = ActiveCell.Value
    On Error Resume Next
    ActiveCell = Range(ActiveWorkbook.Names("SourceCell").RefersTo).Value
    If Err.Number <> 0 Then
        On Error GoTo 0
        Exit Sub
    End If

    On Error GoTo 0
    Range(ActiveWorkbook.Names("SourceCell").RefersTo).Value = vSwap
    ActiveWorkbook.Names("SourceCell").Delete

End Sub[/COLOR][/SIZE][/FONT]
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top