Excel Non contiguous cells

I have been trying to select non contiguous cells in Excel. Contiguous ranges like select Range(“C4:C10”) works but Range(“C5:C5” & “C7:C7”) or any variants I can of thing just do not work.

Have looked in Mac Reference 2004 and looked on the web but not found anything.

Thanks as always for any suggestions.

This works on my system:

tell application "Microsoft Excel"
	activate
	set firstRange to range "C5:C5" of active sheet
	set secondRange to range "C7:C7" of active sheet
	set multRange to union range1 firstRange range2 secondRange
	select multRange
end tell

Note that you will not see both ranges highlighted. It highlights the first, but not the second. However, if you look at the row numbers and the column letters, you will see that they are selected.

Go figure…

Model: Mac Pro (Mid 2010)
AppleScript: 2.7
Browser: Firefox 79.0
Operating System: macOS 10.14

Use a comma to indicate a union of ranges:


select range "C5:C5,C7:C7"

And a space to indicate an intersection of ranges:


select range "B:B 5:5"

Roosterboy

Thank you I had thought I had tried every combination but obviously had not dropped the apostrophes after C5 and before C7.

Learn something every day.

haolesurferdude thanks also for your suggestion, should have thought of the union command but Roosterboy’s solution is simple its the way to go at least for what I was trying to accomplish, namely setting the background color of a range of non contiguous cells.

Peter

I learned something.

Thank you!