I am trying to get the first two cells of an Excel sheet into an array.
I want to loop thru the sheet instead of just using —set mynewArray to (value of range “A1:B123”)
My end game is to make this array a Master format to check many other excel sheets against to see if they retain the same format.
Im sending out a questionnaire to some employees on Excel sheets, when they send them back
I´ll use the Master format array to check them to see if the format is the same as the MASTER Sheet I originally sent them.
I will then run a script on the returned sheets, if the format is the same, to “grade and categorize “the answers.
Loop thru sheet is working ok!
Gets question_num and question_text correctly!
The problem is the array is not being populated!
Im not versed in applescript, but have unsuccessfully looked for a solution.
Thanks for your help!
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
set Row1 to {}
set Row2 to {}
set mynewArray to {{Row1, Row2}} --trying to make two dimension array
tell application "Microsoft Excel"
tell active sheet
try
set my_file to POSIX file "/Users/chanxxx/Documents/Cuestionario de la Guia de Referencia II Nom-035 -3.xlsx"
open my_file
delay 5
-------------- START LOOP THRU EXCEL TO PUT FIRST TWO CELLS OF EACH ROW IN AN ARRAY--------
------------- This section creates and populates the array from Excel sheet --------
repeat with i from 1 to 123 -- stepping forward starting at the top row
set question_num to value of cell ("A" & i) as string -- sets the value of the current cell to the first cell of the current row , a number
set question_text to value of cell ("B" & i) as string -- sets the value of the current cell to the second cell of the current row , a text
if question_num is not equal to "" then -- only gets non empty rows of sheet
------- loop thru columns here ---------------------------
repeat with z from 1 to 2 --num of columns
set item z of (item i of mynewArray) to question_num
set item z of (item i of mynewArray) to question_text
end repeat
end if
end repeat
end try
end tell
end tell
Model: macbook pro
Browser: Safari 604.3.5
Operating System: macOS 10.14