Vilnis Vesma's Excel tip: self-extending tabulationsSometimes you need to set up a spreadsheet with a tabulation that will grow as you add new rows of data from time to time (adding new meter readings each week, for example). Usually there will be formulae in columns of the spreadsheet, and you have to remember to copy the formulae down each time you add new input data.This is a typical example -- a set of meter readings with formulae for calculating the meter advance:
The following macro, attached as worksheet code, will keep your formulae
columns filled down as far as the bottom of the input data:
It is looking for empty cells, because these may be candidates to have formulae copied into them. It decides which ones to populate by scanning up the column. If it encounters a formula in a cell above the target cell (the one it is inspecting), it replicates that formula down the column as far as the target cell. Then it moves on to inspect the next cell in the row, and so on. The effect (in the illustrated example, which is available to download) is that as soon as you add a new reading, the correct formulae magically appear in the calculated column opposite your new data. You can have as many calculated columns as you wish, either side of your input-data columns, and it doesn't matter if the sheet is updated manually or by macros. Anything which extends the table will cause all formula columns to fill down to the row containing the new values. V.V. 25 November, 2005 |