How to switch data between cells?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a quick way to switch data between cells? I.E. Imagine a ranking
system where the data is ever changing. One day I may want to switch the data
from A2 to A5 and A5 to A2. The next may be A7 switching to A1, etc., etc.
Just curious if there is a quick way to do this. I am running excel 2003. Any
and all help is greatly appreciated.
 
One way (using a macro - attach it to a button, keystroke or menu item):

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top