Set selection range to multiple columns like "A,B,F" in NUMBERS

Hello everyone, I’m new here on the forum and I’m happy to be here now :wink:

I have a problem which I unfortunately can not solve myself. Maybe someone has an idea to solve this problem.

I want to select multiple columns in Numbers. For example column A, B and F.

everything I have tried unfortunately does not work.

Here are some of my attempts.

set selection range to column {"A", "B", "F"}
set test to "a"
				set test2 to "c"
				
				set selection range to range test
				tell application "System Events" to key down command
				set selection range to range test2
				tell application "System Events" to key up command

If someone has an idea please let me know, thank you in advance.

Hi. Welcome to MacScripter.

Unfortunately, Numbers’s AppleScript implementation only permits the selection of one continuous range. Something like this:

tell application "Numbers"
	tell table 1 of sheet 1 of document 1
		set endOfRange to name of last cell of column "F"
		set selection range to range ("A1:" & endOfRange)
	end tell
end tell

It’s possible to select more than one range manually, but asking for the result through Numbers’s AppleScript implementation returns a single range covering the ranges actually selected and everything in between. I can’t off-hand think of a scriptable way round this. :confused:

Hello Nigel thank you very much :wink: unfortunately I already thought so.

As Nigel Garvey has already noted, GUI scripting is indispensable to solve this problem. Here I tried to find the shortest GUI way, code that should change little over time. In the absence of a better solution, this solution can be considered acceptable:


on selectNosequentionalColumns(ColumnNames)
	tell application "Numbers" to activate
	repeat with columnName in ColumnNames
		tell application "Numbers" to tell table 1 of sheet 1 of document 1 to ¬
			set selection range to column columnName
		tell application "System Events" to tell process "Numbers" to ¬
			click menu item "Hide Column" of menu 1 of menu bar item "Table" of menu bar 1
	end repeat
	tell application "System Events" to tell process "Numbers" to ¬
		click menu item "Unhide All Columns" of menu 1 of menu bar item "Table" of menu bar 1
end selectNosequentionalColumns

my selectNosequentionalColumns({"A", "B", "F"})