Possibly set up a table, length down the side and width across the rows, then use the index match formula, or sumproduct.

Here is a good start for index match

http://contextures.com/xlFunctions03.html#Index