transpose columns and rows in numbers
I need to transpose columns and rows in Numbers and I do not want to write script to do it. Is there an easier way?
MacBook Pro, iOS 6.1.4, iWork - Numbers
I need to transpose columns and rows in Numbers and I do not want to write script to do it. Is there an easier way?
MacBook Pro, iOS 6.1.4, iWork - Numbers
Your fix for getting it to work in Numbers 2 didn't quite work. Here's the version that worked in Numbers 2:
--Transpose - select range, run, paste transposed values where wanted
try
tell application "Numbers" to tell front document to tell (first sheet whose every table's selection range's class contains range)
set selected_table to first table whose class of selection range is range
tell selected_table
set first_col to the address of the first column of the selection range
set last_col to address of last column of the selection range
set first_row to address of first row of the selection range
set last_row to address of last row of the selection range
set str to ""
repeat with i from first_col to last_col
repeat with j from first_row to last_row
set str to str & (value of cell j of column i of selected_table) & tab
end repeat
set str to str & return -- add line return after row
end repeat
end tell
end tell
set the clipboard to str
on error
display dialog "Select a range first and then try again"
end try
--end script
It didn't seem to like assigning the variable my_selection to be the "selection range." Maybe it has to be declared in some way. I just dispensed with the assignment and it worked. Thanks, this will save some time in creating a mailing list using Numbers.
"She who knows not and knows not that she knows not is a fool, spurn her. She who knows not and knows that she knows not is a child, teach her. She who knows and knows not that she knows is asleep, wake her. She who knows and knows that she knows is a fanatic, kill her." -- ancient proverb
Perhaps you could post here the script that doesn't work, and I'll try to troubleshoot it with Numbers 2. The best way to post a script now seems to be to click 'Use advanced editor' (upper right), the click the >> Syntax Highlighting > Plain.
SG
Hi Ian,
Ah, User Tips seem to be easily accessible again. You posted a nice one today.
With the new ASC format, I still haven't figured out how to post AppleScript with proper indentation.
I'm still feeling a little lost here, but glad to see the helpful leaders are still here!
SG
I got the same error the first time I tried it. I looked back at what I had copied and pasted into Automator, and found that I needed to delete the header and footer that SGIII had included: "--Transpose - select range, run, paste transposed values where wanted" & "--end of script." Once I did that, worked like a charm.
Oh, and SG, just the values from a given cell would be fine. It doesn't need to be a formula. The output from the formula is what I'm after.
Basically, my problem is that when I tell a cell the address of another, on a separate sheet, then drag down to fill a column, the address fills in as a column, rather than as a row. I need it to transpose the addresses so that the row addresses fill in on the column. I hope this makes sense...
I think the problem is that you're missing the $ anchors. $7:$7, not 7:7. Note I have $4$4 in my example. You can set the anchors by checking the Preserve Row after clicking the disclosure triangle in the address token.
SG
Tried that. Still returning "The formula contains a number outside the valid range." Returns the same message even when I change the row to refer to one that I entered in manually, rather than being populated with the "average" formula.
How about a screenshot showing both tables and relevant row numbers and the formula? (I can't see the row numbers of the first table in the last screenshot, and the formula definitely does not include the $).
SG
You're hiding rows 2-5 of the table! That makes it very hard to see what is going on.
Also, from your screenshot I can only see nine values in row 7 of the last table (the data input table), yet you have more than 9 values in column H of the first table. When the formula "runs out" of values in row 7 it complains you are outside the valid range.
SG
A couple things:
First, I figured it out! My problem was that I was not making the target match the original (i.e., to make this formula work, if the data input table is 18 columns wide, the dataframe has to be 18 rows long).
Second, in the picture above, I had entered in the first set of values manually (rows 2–19) and was trying out the formula on a new set (Intermedium), which started down low enough that I had to scroll down a bit to show it. The first two pictures are of the same table, just scrolled differently.
What I did to actually make this work, just to move the values that I've already collected into the dataframe, was create a temporary table on the same sheet with a matching number of rows as there are columns in the original. However, this workaround doesn't solve my issue with wanting to create a master sheet that I can use to collect data later. I'm still unable to enter a particular formula into a cell, then drag that formula down to apply to multiple rows in a column, and have those formulae refer back to a row's worth of columns in a different table. Any thoughts?
Thanks again! This will at least get me through the next few days!
andy563 wrote:
still unable to enter a particular formula into a cell, then drag that formula down to apply to multiple rows in a column, and have those formulae refer back to a row's worth of columns in a different table. Any thoughts?
Isn't that *exactly* what my example upthread does?
SG
Yes, but with the workaround, it still requires making a custom-sized table to populate with the formulae, rather than having the formulae be integrated into the larger dataframe. Unless I'm completely missing something, which is entirely possible.
Not sure what you mean by "custom-sized table" and "larger dataframe." In any case if your input is horizontal (in a row) and your output (in the "data frame" column) is vertical, then you can use TRANSPOSE in the output table as demonstrated.
SG
I mean that, in order to get the formula to work, I have to create a temporary table of the inverted proportions (e.g., 15x1) of the original input (e.g., 1x15) that I can copy and paste the values from into the master list (i.e., the data frame), in order to export in a format that is readable by the statistics package, R. I think I may have figured out an additional workaround to get this to work. I'll try and create a new sheet and fill it with the temporary tables (i.e., the 15x1 I mentioned above), then tell the master dataframe to go look for them there, instead of in the input table. I'll let you know if it works.
transpose columns and rows in numbers