#1   Report Post  
William Wolfe
 
Posts: n/a
Default Swap Cells

Is there an easy way to select two cells and swap them?

Thanks,

W Wolfe


  #2   Report Post  
Tushar Mehta
 
Posts: n/a
Default

Depends on your definition of easy. Temporarily, click and drag the
first cell to an empty cell. Click and drag the 2nd cell to the 1st
cell. Click and drag the temporary cell to the 2nd cell.

Depending on how far apart the cells are, it may be easier to use
cut+paste rather than click-and-drag.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Multi-disciplinary business expertise
+ Technology skills
= Optimal solution to your business problem
Recipient Microsoft MVP award 2000-2005

In article ,
says...
Is there an easy way to select two cells and swap them?

Thanks,

W Wolfe



  #3   Report Post  
JE McGimpsey
 
Posts: n/a
Default

From the archives:

http://groups.google.com/advanced_gr...ugroup=*excel*

Check out


http://groups-beta.google.com/group/...worksheet.func
tions/browse_frm/thread/5c12eaff46290526/5396f1415d9da591

or http://tinyurl.com/8etsl

In article ,
"William Wolfe" wrote:

Is there an easy way to select two cells and swap them?

  #4   Report Post  
dominicb
 
Posts: n/a
Default


Good afternoon William

You could use VBA thus:

Sub Swap()
Dim cval(), cadd()
a = 1
ReDim cval(2), cadd(2)
For Each usrcell In Selection
cval(a) = usrcell.Value
cadd(a) = usrcell.Address
a = a + 1
Next usrcell
Range(cadd(1)).Select
ActiveCell = cval(2)
Range(cadd(2)).Select
ActiveCell = cval(1)
End Sub

Just highlight the two cells and run the macro.

HTH

DominicB


--
dominicb
------------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932
View this thread: http://www.excelforum.com/showthread...hreadid=379617

  #5   Report Post  
JE McGimpsey
 
Posts: n/a
Default

This is a bit dangerous -

If only one cell is selected, the data is deleted (by ActiveCell =
cval(2)) and a run-time error is generated by Range(cadd(2)).Select.

Also, if more than two cells are selected, a subscript out of range
error will be generated, though in that case no data is destroyed.

I would at least put a line in like

If Selection.Count < 2 Then Exit Sub

In article ,
dominicb
wrote:

Good afternoon William

You could use VBA thus:

Sub Swap()
Dim cval(), cadd()
a = 1
ReDim cval(2), cadd(2)
For Each usrcell In Selection
cval(a) = usrcell.Value
cadd(a) = usrcell.Address
a = a + 1
Next usrcell
Range(cadd(1)).Select
ActiveCell = cval(2)
Range(cadd(2)).Select
ActiveCell = cval(1)
End Sub

Just highlight the two cells and run the macro.

HTH

DominicB

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help adding text values Texas-DC_271 Excel Worksheet Functions 7 January 15th 05 11:14 PM
Is there a quick shortcut to swap the data in two cells? eburris Excel Discussion (Misc queries) 1 January 13th 05 11:38 PM
To safety merge cells without data destroyed, and smart unmerge! Kevin Excel Discussion (Misc queries) 0 December 30th 04 07:17 AM
Heps to design Locked/Unlocked cells in protected worksheet Kevin Excel Discussion (Misc queries) 0 December 30th 04 07:09 AM
Convert data of cells to any type: Number, Date&Time, Text Kevin Excel Discussion (Misc queries) 0 December 30th 04 06:55 AM


All times are GMT +1. The time now is 08:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"