Is there an easy way to swap the contents of two cells in Microsoft Excel?

By easy, I mean either a keyboard shortcut or menu item, without involving copying to temporary cells or writing VBA scripts or anything like that. In other words, I'm looking for a way to just select two cells and click some menu item or press some key combination that will swap their contents. Surely, there has got to be a way to do this?

link|improve this question
This seems like a very specific implementation of a sort, and if its not already present in the advanced sorting options, I'd be surprised if you can find it elsewhere, as a non-VBA solution – drapkin11 Mar 14 '11 at 16:29
feedback

2 Answers

By easy, I mean either a keyboard shortcut or menu item, without involving copying to temporary cells or writing VBA scripts or anything like that. I'm looking for a way to just select two cells and click some menu item or press some key combination that will swap their contents.

Why impose this restriction? Creating a macro makes this trivial. As far as I know, it can't be done any other way. You can assign the macro to a button or hotkey.

Sub Swap()     
    If Selection.Count <> 2 Then     
         MsgBox "Select 2 cells (only) to swap."     
         Exit Sub     
    End If     
    Set trange = Selection     
    If trange.Areas.Count = 2 Then     
         temp = trange.Areas(2)     
         trange.Areas(2) = trange.Areas(1)     
         trange.Areas(1) = temp     
    Else     
         temp = trange(1)     
         trange(1) = trange(2)     
         trange(2) = temp     
    End If     
End Sub     
link|improve this answer
I'm not a VBA expert and have neither the time nor the inclination to become one. I also frequently use many different computers. It would be nice to have swapping available on every computer I use for Excel, without having to look-up the code for the VBA macro that does it, so that I can bind it to a hotkey. – Dan Moulding Mar 14 '11 at 19:16
2  
@Dan It would be nice if everyone could have their pet functionality built into Excel, but then it would become even more a bloated mess than it already is. There is a reason why Excel has a macro language, to automate repetitive tasks like this. I posted code found through a google search. You don't have to be an expert. – ghoppe Mar 14 '11 at 19:29
+1 vba is the way excel allows you to add your pet functions. there are also ways of making that vba avaliable on many computers, to just yourself or to all (eg personal workbook, or addins) – chris neilsen Mar 18 '11 at 23:34
I would hardly call swapping the content of two cells / rows /columns to be a pet function. – Nicolai Feb 17 at 11:35
@Nicolai One person's essential feature is another person's pet function. If it's not a "pet function" please let me know what spreadsheet software has the capability built in. I'm genuinely interested to know why you view such a feature as essential. – ghoppe Feb 17 at 22:46
show 1 more comment
feedback
up vote 2 down vote accepted

No. There is no way to swap the contents of two cells in Excel, without writing your own macro to do it.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.