h a l f b a k e r yThis product is not intended to diagnose, treat, cure or prevent any disease.
add, search, annotate, link, view, overview, recent, by name, random
news, help, about, links, report a problem
browse anonymously,
or get an account
and write.
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 | |
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.
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. |
|
|
macro: move A to Z, B to A, Z to B, delete Z. |
|
|
baked in some assemblers. |
|
|
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 |
|
|
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. |
|
|
someone wrote a macro that achieves the functionality you described - link |
|
|
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. |
|
|
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:
|
|
|
(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) |
|
|
neither of these algos are relevant or well advised in this situation. |
|
|
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. |
|
|
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): |
|
|
- but how could that work for floating point numbers? Stupid question i know, but i'm not a programmer. |
|
|
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. |
|
|
Sorry [jutta], i missed your note because i was typing. |
|
|
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. |
|
|
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 |
|
|
That's sort of what i meant in the first anno. |
|
|
Good idea - wouldn't this be simply swap? (Where does the 'copy' come into it? |
|
|
What's a spreadsheet? (that bone's not mine by the way) |
|
|
//the dictionary definiton // |
|
|
Thanks [21], but I have a feeling [xenzag] was being facetious... |
|
|
This is fantastic. [+] How come this is not baked in operating systems? To undo, just swap again. |
|
|
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! |
|
|
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! |
|
| |