Numbers - transposing a worksheet


I am new in manipulating a MAC number worksheet in AppleScript. I’ve done a research for “Numbers” on this forum and could not find any examples.

I want to transpose all rows of a worksheet into columns.

The current worksheet contains 4 fields (Obs, Date, Hours and okWh). Each row contains a time period for a given day. The hours are always the same (00:00, 04:00, 08:00, 12:00, 16:00 and 20:00) for up to 2190 rows (365 days). The file is to filled once a month.

Kind regards!

tell application “Numbers”
tell the first table of the active sheet of document 1
set numbofrec to row count

	repeat with currentrow from 1 to row count
		set info to value of cell "D" & (currentrow as string)
		display dialog "Rows: " & numbofrec & " row: " & currentrow & " data: " & info
		set currentrow to currentrow + 1
	end repeat
end tell

end tell
end tell[/AppleScript]

Model: MacBook Pro Monterey version 12.2.1
Browser: Safari 605.1.15
Operating System: macOS 12

If you have a recent version of Numbers (eg 11.2) you can do this much more effectively with a pivot table

You could do it with AppleScript, but it would be painfully slow as it would involve creating a new table and then duplicating the data for at least 2190 individual cells (more in leap years…)

WOW, I just do not understand why I did not think of that.

You are absolutely correct!

I’ve just done it and it was a peace of cake.

Many thanks!

:slight_smile: Glad I could help!