Hi there,
Please can someone tell me why I might get the following error from the code below?
Can’t get item 5 of {}
It’s really strange because when I watch the values of (item c of list2 as number) prior to the line below all seems ok, however the error then occurs?
set item totalsPos of timeTotals to (item totalsPos of timeTotals) + (item c of list2 as number)
Without the test data this is a little tricky I guess, though any educated guesses would be appreciated.
Thanks.
Here’s the code:-
set timeTotals to {}
repeat with i from 1 to 31
tell application "Microsoft Excel"
activate
activate object worksheet i of active workbook
set list1 to value of every cell of range ("B12:B31")
set list2 to value of every cell of range ("F12:F31")
set list3 to value of every cell of range ("G12:G31")
end tell
set c to 1
repeat with ThisItem in list1
set customerCodes to {"AAA", "BBB", "CCC", "DDD", "EEE", "FFF", "GGG", "HHH", "III"}
repeat with thisCode in customerCodes
set totalsPos to list_position(thisCode as text, customerCodes)
if (ThisItem as text) = thisCode as text then
set item totalsPos of timeTotals to (item totalsPos of timeTotals) + (item c of list2 as number)
end if
end repeat
set c to c + 1
end repeat
end repeat
on list_position(this_item, this_list)
repeat with i from 1 to the count of this_list
if item i of this_list is this_item then return i
end repeat
return 0
end list_position
AAA & BBB & CCC & DDD & EEE & FFF & GGG & HHH & III
Thanks in advance,
Nick