set ListToExcel to {}
repeat with rowNum from 1 to 10
set oneRowsList to {}
repeat with colNum from 1 to 10
copy ("row-" & rowNum & ",col-" & colNum) to end of oneRowsList
end repeat
copy oneRowsList to end of ListToExcel
end repeat
tell application "Microsoft Excel"
set value of range "A1:J10" to ListToExcel
end tell
If you are given a list {v1,v2,v3,…v(r*c)} that you want to add to a sheet, you would need either the column or row count for the destination range. With that, you could do something like
set myList to {"v1", "v2", "v3", "v4", "v5", "v6"}
set rowsCount to 3
set myExcelList to {}
set pointer to 0
repeat with rowNum from 1 to rowsCount
set oneRowsList to {}
repeat with colNum from 1 to (count of myList) / rowsCount
set pointer to pointer + 1
copy item pointer of myList to end of oneRowsList
end repeat
copy oneRowsList to end of myExcelList
end repeat
tell application "Microsoft Excel"
set value of (get resize range "a1" row size rowsCount column size ((count of myList) / rowsCount)) to myExcelList
end tell
Thank you both (also mikericson) for your hints.
But I have the revers question: I want send a list of values to a column in Excel. to send a row is easy: just copy the List to the Excel-range, but how to do the same with a column?
If you want to use a loop instead of referring to the range, mikerickson solution works.
How are use viewing the list?
Are you looking at the result window or are you putting a log statement in the event log?
They might return what seems to be different results.
On the first approach I didn’t understand, what the script does. So I tried it now “blind” - and yes, it works with a little modification! I’m now gooing to analyze and adapt it on my script.
Thank you very much!