View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Brian Withun Brian Withun is offline
external usenet poster
 
Posts: 9
Default automatically change column references in formulas

You want your formulas in SheetB to be relative references, not
absolute references.

If, for instance, you have SheetB hard-coded to calculate its values
for the month of January (SheetA ColumnB),
SheetB!$C7 = SheetA!B2-SheetA!B3

change it to:
SheetB!$C7 = OFFSET(SheetA!A2,0,Month)-OFFSET(SheetA!A3,0,Month)

This new formula will allow SheetB to calculate based on whichever
column/month in SheetA you want, depending on the value of "Month".
(where 1 <= Month <= 12)

You could then create a Validate cell (SheetB!C4) which allows you to
pick a month from a drop-down list. If SheetA has headings (in SheetA!
$B$1:$M$1), and your drop-down picklist lets you select one of those
very headings, then all you have to do is lookup (using MATCH()) your
drop-down selection within the range of your column headings and
you'll get an actual index between 1 and 12. Substitute this in for
Month below:

(I've created the name "Headings" to refer to the range =SheetA!$B$1:$M
$1, which are my column headings [Jan-Dec] )

SheetB!$C7 =OFFSET(SheetA!A2,0,MATCH(C4,Headings,0))-OFFSET(SheetA!
A3,0,MATCH(C4,Headings,0))

Having done this, I can pick a new month in cell SheetB!C4 and my
formula in SheetB!C7 does its calculation for the month I chose.

Hope this is clear.

Brian Herbert Withun