Hi agin,
This is my version of AppleScript for Numbers '09. I hope you like it.
property dN : "DocumentName" -- change to match your document name
property sN : "SheetName" -- change to match your sheet name
property tN : "TableName" -- change to match your table name
property sC : 2 -- column "Jan" - change to match your table
property eC : 13 -- column "Dec" - change to match your table
property tC : 14 -- column "Difference between the first and last values" - change to match your table
property hR : 1 -- the number of header rows - change to match your table
property fR : 0 -- the number of footer rows - change to match your table
tell application "Numbers"
tell documentdN'ssheetsN'stabletN
repeat with i from (hR + 1) to (row count - fR)
set vList1 to value of cells sC thru eC of row i
set {firstValue, lastValue} to my removeZeroItems(vList1)
set value of cell tC of row i to (lastValue - firstValue)
end repeat
end tell
end tell
-- A handler to return a list of the first- and last-nonzero items in a received list
on removeZeroItems(aList)
set newList to {}
repeat with theItem in aList
if theItem as integer is not 0 then set newList to newList & theItem
end repeat
return {the first item, the last item} of newList
end removeZeroItems