Half a croissant, on a plate, with a sign in front of it saying '50c'
h a l f b a k e r y
Bunned. James Bunned.

idea: add, search, annotate, link, view, overview, recent, by name, random

meta: news, help, about, links, report a problem

account: browse anonymously, or get an account and write.

user:
pass:
register,


                                                     

Please log in.
Before you can vote, you need to register. Please log in or create an account.

Copy > Swap

Quicker than: Copy > Paste, Copy > Paste, Copy > Paste
  (+25, -2)(+25, -2)(+25, -2)
(+25, -2)
  [vote for,
against]

I want to swap the content of two cells in a spreadsheet but it requires moving the 1st item to a vacant cell, then moving the 2nd item to the 1st cell, then moving the 1st item to the 2nd cell. Why not Copy the 1st item, select the 2nd item and hit Ctrl-[vacant key stroke] and have them swap?

This can also be used on graphics products (I'd love it in InDesign and Illustrator when my Editor asks me, "Can we just try them the other way round?") in text applications and no doubt a whole host of other software.

Gnome.

theleopard, Feb 26 2009

LockerGnome Answer ('s true) http://help.lockerg...-ftopict629061.html
well thought-out script [loonquawl, Feb 26 2009]

comp.lang.c FAQ 3.3b http://c-faq.com/expr/xorswapexpr.html
I'm still none the wiser, mind. [theleopard, Feb 26 2009]

[link]






       Yes, i can see that would be good. I never use spreadsheets because i feel irrationally that i have more control over a piece of paper with numbers i've written on it. I also like APL. However, this reminds me of FORTH stack operations like DUP, OVER, SWAP, DROP and so forth, and i wonder if they have spreadsheet equivalents.
nineteenthly, Feb 26 2009
  

       macro: move A to Z, B to A, Z to B, delete Z.   

       baked in some assemblers.
FlyingToaster, Feb 26 2009
  

       I can't see any problem with this idea. I can even imagine it being useful at times. A short .vbs macro would do the job in excel - instead of copying to clipboard assign another shortcut that just stores the current selection reference - and a matching one which reads the (new) selection reference and exchanges the content of the two.   

       Ctrl+Shift+C / Ctrl+Shift+V could work
vincevincevince, Feb 26 2009
  

       The macro method is a bit clunky in my view and you would need to tell it which cells that you want to swap anyway, which is hardly quicker than the copy paste method. So + from me. This function would indeed be useful.
DrBob, Feb 26 2009
  

       someone wrote a macro that achieves the functionality you described - link
loonquawl, Feb 26 2009
  

       A slightly related "trick" involving a swap with no intermediary value... You can do this with the Xor function if the items are numerical (or can be treated numerically in a linear fashion)   

       In C, this looks like the following:
int x,y;
x=9;
y=34;
x^=y^=x^=y;
  

       Oh, and this would also (possibly, if they are not next to eachother) require the ability to do multiple selections, something i've wanted in excel/word/everywhere for quite some time.
ericscottf, Feb 26 2009
  

       Huh?
theleopard, Feb 26 2009
  

       I think it's a binary thing - if you XOR a pair of binary numbers enough times, it switches them around (I think)   

       e.g. If we have 2 eight-bit numbers, x=5 and y=14.
If you look at the binary they look like this
x = [00000101] and
y = [00001110]
  

       when you XOR two numbers, the result is 1 where ONLY one of the values is one. So a single XOR results in:
  

       x XOR y = [00001011]....   

       (this is the bit where I run out of steam - but it's something like that, right?)   

       [edit] much later, and more steam...   

       so we'd XOR'd x and y and got [00001011] = 11   

       Now we XOR y and the last value stored in x
[00001011] = 11
and
[00001110] =14
[00000101] = 5 so
y is now = 5
  

       And finally, if we XOR
[00001011] and the new y
[00000101]
we get
[00001110] which is the same as the original y.
Which means that two values have swapped places without a 'holder' place z.
  

       Since any arbitrary string of characters can be expressed by a binary number of a given length, it should be possible to utilise this method for almost anything - as long as you encode it in a reliable manner (floating points would have to be converted to direct representations, or the mantissas and other parts dealt with in silos)   

       So while it's true that the statement:
x^=y^=x^=y;
might be interpreted ambiguously by a parser, the underlying principal of repeated XORs holds true (the same way a perfect riffle shuffle repeated 8 times will return a deck to its original order)
zen_tom, Feb 26 2009
  

       neither of these algos are relevant or well advised in this situation.
Spacecoyote, Feb 26 2009
  

       Yeah, keep up you two.
theleopard, Feb 26 2009
  

       I want this in the OS: a "swap the names of the two selected files" option. I'd also like a "swap Vista for XP" button, but I'm probably not getting one.
wagster, Feb 26 2009
  

       I don't follow that and i can't see how it would be OK with floating point values. I can see you could maybe swap unsigned binary values in adjacent memory locations by doing this (in FORTH, depending on endianism):   

       X @ Y @ 65536 D* +   

       - but how could that work for floating point numbers? Stupid question i know, but i'm not a programmer.
nineteenthly, Feb 26 2009
  

       Please see 3.3b of Steve Summit's comp.lang.c Frequently Asked Questions list, preferably without adding more off-topic nonsense to this already completely bogus bit of grandstanding.
jutta, Feb 26 2009
  

       Sorry [jutta], i missed your note because i was typing.
nineteenthly, Feb 26 2009
  

       I've now read the FAQ and it seems to confirm what i thought, but i think i thought them for the wrong reasons.   

       I don't see how it could work reliably. Can you apply Boolean operators to floating point numbers in C? If not, how could it work? The result of an exclusive or operation on two constants would, it seems to me, depend on whether you thought of them as numbers multiplied by ten raised to the power of other numbers, or as a single binary number. A hundred XORed with fifty as a binary number is 01100100 XOR 00110010, which is 01010110, or eighty-six, but considering them as multiples of powers of ten, the tens would cancel out and become zeroes, and once that's happened there's no point in going any further because the result would be the same unless the word length was different. So, what i'm saying is, how can that possibly work? How can you do Boolean operations on floating point numbers? Wouldn't they have to be different data types?   

       I've probably just revealed my vast ignorance, sorry.
nineteenthly, Feb 26 2009
  

       You could get the swap functionality and more if there were a stacked-copy operation that would remember multiple copy ops, not just the most recent. Thus, as you press Ctrl-V multiple times (without changing selection), you cycle back through your stack of copied bits until you see the one you want.   

       To swap contents of cells A & B, do this: Select cell A: Copy Select cell B: Copy, Paste, Paste Select cell A: Paste
luxlucet, Feb 26 2009
  

       That's sort of what i meant in the first anno.
nineteenthly, Feb 26 2009
  

       good idea [+]
hippo, Feb 27 2009
  

       Good idea - wouldn't this be simply swap? (Where does the 'copy' come into it?
energy guy, Feb 27 2009
  

       What's a spreadsheet? (that bone's not mine by the way)
xenzag, Feb 27 2009
  

       //the dictionary definiton //   

       Thanks [21], but I have a feeling [xenzag] was being facetious...
theleopard, Mar 02 2009
  

       This is fantastic. [+] How come this is not baked in operating systems? To undo, just swap again.
placid_turmoil, Mar 03 2009
  

       I assume this is from Excel? Um... try holding the SHIFT key and dragging a cell from the margin. .....SWAP!   

       Works for whole columns, block of cells, etc.   

       See what CTRL-drag does, too!
not_only_but_also, Mar 03 2009
  

       Aha! Well done, not-only. It's not really a swap function though, it just inserts your selection into the position of the target cell and shifts the target cell to the left, so it only works for adjacent items, but it's progress of a kind!
DrBob, Mar 03 2009
  
      
[annotate]
  


 

back: main index

business  computer  culture  fashion  food  halfbakery  home  other  product  public  science  sport  vehicle