Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

AppleScript for transposing only a range

Dear all,

Has anyone come across or written an AppleScript that would transpose a selected range of cells in a table in Numbers without transposing the whole table?

I was thinking of a script that would copy the cells somewhere else in the computer's memory, transpose those, paste the transposed to the buffer and, then, let you know. One, then, can simply paste them back to anywhere in their table they like.

I know the "Transpose Rows and Columns" option under the Table menu option but, as you would know, it transposes the whole table or you have to copy & paste the row or column outside to a new table and copy&paste them back after being transposed. Thank you!

Alper

P.S. I am using Numbers 4.3.1 on macOS High Sierra (10.13.3)

Posted on Feb 10, 2018 1:11 PM

Reply
Question marked as Best reply

Posted on Feb 10, 2018 4:38 PM

You can try the script below. It will transpose values but won't convert formulas.


SG


--Select range, run, paste transposed values where wanted

set text item delimiters to tab

tell application "Numbers" to tell front document to tell active sheet

set selTable to first table whose class of selection range is range

tell selTable

set mySelection to selection range

set firstCol to address of first column of mySelection

set lastCol to address of last column of mySelection

set firstRow to address of first row of mySelection

set lastRow to address of last row of mySelection

set pasteStr to ""

repeat with i from firstCol to lastCol

set strRowLst to {}

repeat with j from firstRow to lastRow

copy (value of cell j of column i of selTable) to end of strRowLst

end repeat

set pasteStr to (pasteStr & strRowLst as text) & return

end repeat

end tell

end tell

set the clipboard topasteStr

display notification "Ready to paste transposed values" with title "Numbers"

Similar questions

2 replies
Question marked as Best reply

Feb 10, 2018 4:38 PM in response to bpaksoy

You can try the script below. It will transpose values but won't convert formulas.


SG


--Select range, run, paste transposed values where wanted

set text item delimiters to tab

tell application "Numbers" to tell front document to tell active sheet

set selTable to first table whose class of selection range is range

tell selTable

set mySelection to selection range

set firstCol to address of first column of mySelection

set lastCol to address of last column of mySelection

set firstRow to address of first row of mySelection

set lastRow to address of last row of mySelection

set pasteStr to ""

repeat with i from firstCol to lastCol

set strRowLst to {}

repeat with j from firstRow to lastRow

copy (value of cell j of column i of selTable) to end of strRowLst

end repeat

set pasteStr to (pasteStr & strRowLst as text) & return

end repeat

end tell

end tell

set the clipboard topasteStr

display notification "Ready to paste transposed values" with title "Numbers"

AppleScript for transposing only a range

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.