View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Ken Johnson
 
Posts: n/a
Default MIcrosoft Excel: should allow sheet increase by 1 on fill down

Hi Albert,
I must have just missed your last message last night. I'm in Sydney
Australia and got to bed at 3 am, the time on your message is 3:05 am.
Hope you're not in a rush.
In its simplest form the formula is:

=IF(INDIRECT(LEFT("'000",4-INT(LOG(ROW()-1))) & ROW()-1
&"'!$E$3")="","",IF(INDIRECT(LEFT("'000",4-INT(LOG(ROW()-1))) & ROW()-1
&"'!$E$3")0,INDIRECT(LEFT("'000",4-INT(LOG(ROW()-1))) & ROW()-1
&"'!$E$3")))

There are a couple of important thing to keep in mind:

1. It uses the ROW() function to increment the referencing as you fill
down the column you are using for this formula

2. I have assumed row 1 is needed for a heading, consequently, as it
stands it will only start referencing the first worksheet (0001) if it
is pasted into row 2 before the fill down. The reason being, in row 2
the function ROW() returns the number 2, then when the 1 is subtracted
you end up with 1, (ROW() -1 = 2, for row 1).
If you don't have a heading and you must start in row 1 then just
delete every "-1".
If you need to start further down the column than row 2 then replace
every "-1" with "-n", where n is one less than the row number
of the row in which you are starting the formula eg if you must start
in row 3 then the formula in row 3 should be:

=IF(INDIRECT(LEFT("'000",4-INT(LOG(ROW()-2))) & ROW()-2
&"'!$E$3")="","",IF(INDIRECT(LEFT("'000",4-INT(LOG(ROW()-2))) & ROW()-2
&"'!$E$3")0,INDIRECT(LEFT("'000",4-INT(LOG(ROW()-2))) & ROW()-2
&"'!$E$3")))

You might be able to make the formula more fail-safe and portable by
replacing those numbers with a formula that counts the rows above your
starting row (I'm not too sure), but it's already complex enough.


3. A large part of the formula's complexity is due to the way the
sheets are numbered with the leading zeros. If there were no leading
zeroes the formula (starting in row 2) would just be:

=IF(INDIRECT("'" & ROW()-1 & "'!$E$3") = "", "",
IF(INDIRECT("'" & ROW()-1 & "'!$E$3") 0,INDIRECT("'" &
ROW()-1 &"'!$E$3")))

4. If you fill down further than there are worksheets you will see the
#REF! error in the cells that have exceeded the number of worksheets,
but that's no big deal.

5. When reading the formula the '' and ' are easily confused.
Where you see "' it's " followed by '. Where you see ""
it's " followed by ".

Sorry for being slow and long winded. Even before I realised there
would be a problem with the leading zeros I thought I was going to have
a problem getting the formula to result in a blank when $E$3 is blank.
You see, say A1 has =INDIRECT(B1) and B1 contains the address C1 then
A1 will show 0 when C1 is blank. As it turned out this problem does not
occur when using INDIRECT the way we have here.
Hope this makes sense! I too am self taught and unfortunately I'm a
lousy teacher and an even worse student

Ken Johnson