View Single Post
Or, if you need to select only a subset of rows to fill (rather than selecting and filling a whole column) something like the following:

Code:
property pTitle : "Fill rows with dates/numbers"
property pVer : "0.2"

-- FILL DATE OR NUMBER COLUMN WITH VALUES
-- BASED ON THE VALUES IN THE FIRST ONE OR TWO 
-- SELECTED ROWS

tell application id "OOut"
	if (count of documents) < 1 then return
	tell front document
		set lstRows to selected rows
		set lngRows to count of lstRows
		if lngRows < 3 then
			display dialog ¬
				"Select two or more rows," & return & return & ¬
				"(With at least a start value in the relevant column of the first selected row)." buttons "OK" default button "OK" with title pTitle & "    " & pVer
			return
		end if
		
		-- CHOOSE A DATE OR NUMBER COLUMN
		set refCols to a reference to (columns where type is date or type is number)
		if (count of refCols) < 1 then
			display dialog ¬
				"Requires at least one column of type date or number." buttons "OK" default button "OK" with title pTitle & "    " & pVer
			return
		end if
		set varChoice to choose from list (name of refCols) as list with prompt ¬
			"Column to fill:" with title pTitle & "   " & pVer
		if varChoice is false then return
		set oCol to column named (first item of varChoice)
		set {eType, idCol} to {type, id} of oCol
		
		-- GET VALUES FROM THE FIRST (AND PERHAPS SECOND) ROWS
		set {varStart, varNext} to {value of cell id idCol of item 1 of lstRows, ¬
			value of cell id idCol of item 2 of lstRows}
		
		set varDelta to 1
		set iStart to 2
		
		if eType = number then
			if varNext ≠ missing value then
				set iStart to 3
				set varDelta to varNext - varStart
			end if
			
			-- FILL REMAINING CELLS WITH NUMBERS
			repeat with i from iStart to lngRows
				set value of cell id idCol of item i of lstRows to varStart + (varDelta * (i - 1))
			end repeat
		else -- date
			if varNext ≠ missing value then
				set varDelta to ((varNext - varStart) / days) as integer
				set iStart to 3
			end if
			
			-- FILL REMAINING CELLS WITH DATES
			repeat with i from iStart to lngRows
				set value of cell id idCol of item i of lstRows to varStart + (varDelta * (i - 1) * days)
			end repeat
		end if
	end tell
end tell

Last edited by RobTrew; 2011-12-20 at 11:20 AM..