i.e. I have 3 sheets called 'May 19', 'May 18' & 'May 17'. Formulas in 'May
19' reference cells in 'May 18', formulas in 'May 18' references cells in
'May 17' and so on.
The problem occurs when I copy a sheet. If I copy sheet 'May 19' and rename
it 'May 20' I want 'May 20' formulas to reference sheet 'May 19' but they
instead reference sheet 'May 18' because I copied the 'May 19' sheet.
Is there anyway to reference the adjacent sheet automatically without having
to change the formulas?
Function NextSheetName() As String
Application.Volatile True
On Error Resume Next
NextSheetName = "'" & Application.Caller.Worksheet.Next.Name & "'"
If Err.Number <> 0 Then
NextSheetName = vbNullString
End If
End Function
Function PreviousSheetName() As String
Application.Volatile True
On Error Resume Next
PreviousSheetName = "'" &
Application.Caller.Worksheet.Previous.Name & "'"
If Err.Number <> 0 Then
PreviousSheetName = vbNullString
End If
End Function
Close the VBA editor and return to Excel. Now, you can use
NextSheetName and PreviousSheetName in formulas with INDIRECT. For
example, to get the value of A1 on the sheet following the current
sheet, use
=INDIRECT(NextSheetName()&"!A1")
Similarly, for the previous sheet,
=INDIRECT(PreviousSheetName()&"!A1")
NextSheetName and PreviousSheetName always return the sheet after or
before the sheet that contains the formula that called them. If you
move sheets around, the formulas will still return the newly next and
previous sheet names.
You'll get an error if you call NextSheetName from the last sheet in
the workbook or if you call PreviousSheetName from the first worksheet
in the workbook.
Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
=INDIRECT("'"&MID(CELL("filename",A1),
FIND("]",CELL("filename",A1))+1,
FIND(" ",CELL("filename",A1))-FIND("]",CELL("filename",A1)))&
TRIM(RIGHT(CELL("filename",A2),2))-1&"'!A1")
HTH
Steve D.
"mlman" <ml...@discussions.microsoft.com> wrote in message
news:28E67B7A-92B2-49D4...@microsoft.com...
The A1s within CELL() are only a way for CELL() to reference the sheet
containing the formula, and can refer to any cell within that sheet.
"Steve Dunn" <st...@sky.com> wrote in message
news:OHfcwCM%23KH...@TK2MSFTNGP06.phx.gbl...