+ Reply to Thread
Results 1 to 2 of 2

Swapping two cells?

  1. #1
    Registered User
    Join Date
    01-17-2005
    Posts
    2

    Swapping two cells?

    Maybe I am missing this, but .......

    Is there a way to just swap two cells? A way to select say c4 and c6, just hit a swap button or hot key?

    Thanks

  2. #2
    Forum Contributor
    Join Date
    01-11-2004
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    388
    Hi!

    Yes: using VBA/macros.

    The following by JE McGimpsey does the job. Set up a button or trigger of some kind. Select 2 cells while holding down the ctrl key. Run it. Run it again to toggle back to where you started.

    Public Sub SwapCells()
    Dim vTemp As Variant
    With Selection
    If .Count <> 2 Then
    MsgBox "2 cells only."
    Else
    If .Areas.Count = 2 Then
    vTemp = .Areas(1).Cells.Value
    .Areas(1).Cells.Value = .Areas(2).Cells.Value
    .Areas(2).Cells.Value = vTemp
    Else
    vTemp = .Cells(1).Value
    .Cells(1).Value = .Cells(2).Value
    .Cells(2).Value = vTemp
    End If
    End If
    End With
    End Sub

    It swaps values, not formulae.

    Alf

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1