Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Formula with the last spreadsheet of workbook

Hi all,

I have workbook with the spreadsheets "Input", "Year 1", "Year 2", "Year 3",
.....
Workbook has different number of spreadsheets. Last spreadsheet name is
"Year 5" or "Year 6" or "Year 7" ... and it depends how many spreadsheets
are in workbook.

On the first sheet "Input" I have formula which refers to the last
spreadsheets cells (sometimes it is "Year 7" and sometimes "Year 9" ... and
so on).
Let this formula is:
='Year 7'!A1+'Year 7'!B1

How I can write universal formula (or macro) there instead concrete
spreadsheets names will be reference to the last spreadsheet name (sometimes
it is "Year 6", sometimes "Year 9" and so on) of workbook.

Thank you in advance.
Best wishes,
Lado


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 336
Default Formula with the last spreadsheet of workbook

Go into the VB Editor (Alt-F11) and then choose Insert, Module to place a new
module in your workbook. Paste the following into it and then you can use
=LastSheet(A1)+LastSheet(A2) etc.

Function LastSheet(cellref) As String
LastSheet = Worksheets(Worksheets.Count).Range(cellref.Address )
End Function


"L.K." wrote:

Hi all,

I have workbook with the spreadsheets "Input", "Year 1", "Year 2", "Year 3",
.....
Workbook has different number of spreadsheets. Last spreadsheet name is
"Year 5" or "Year 6" or "Year 7" ... and it depends how many spreadsheets
are in workbook.

On the first sheet "Input" I have formula which refers to the last
spreadsheets cells (sometimes it is "Year 7" and sometimes "Year 9" ... and
so on).
Let this formula is:
='Year 7'!A1+'Year 7'!B1

How I can write universal formula (or macro) there instead concrete
spreadsheets names will be reference to the last spreadsheet name (sometimes
it is "Year 6", sometimes "Year 9" and so on) of workbook.

Thank you in advance.
Best wishes,
Lado



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Formula with the last spreadsheet of workbook

Martin,

Thank you so much. It's great.

Lado


"Martin" wrote in message
...
Go into the VB Editor (Alt-F11) and then choose Insert, Module to place a
new
module in your workbook. Paste the following into it and then you can use
=LastSheet(A1)+LastSheet(A2) etc.

Function LastSheet(cellref) As String
LastSheet = Worksheets(Worksheets.Count).Range(cellref.Address )
End Function


"L.K." wrote:

Hi all,

I have workbook with the spreadsheets "Input", "Year 1", "Year 2", "Year
3",
.....
Workbook has different number of spreadsheets. Last spreadsheet name is
"Year 5" or "Year 6" or "Year 7" ... and it depends how many
spreadsheets
are in workbook.

On the first sheet "Input" I have formula which refers to the last
spreadsheets cells (sometimes it is "Year 7" and sometimes "Year 9" ...
and
so on).
Let this formula is:
='Year 7'!A1+'Year 7'!B1

How I can write universal formula (or macro) there instead concrete
spreadsheets names will be reference to the last spreadsheet name
(sometimes
it is "Year 6", sometimes "Year 9" and so on) of workbook.

Thank you in advance.
Best wishes,
Lado





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 336
Default Formula with the last spreadsheet of workbook

No problem Lado but looking at Ardus' reply reminded me that it can get
annoying that this function doesn't recalculate without Application.Volatile
(also it shouldn't strictly have As String at the end!). Could you change it
to:

Function LastSheet(cellref)
Application.Volatile
LastSheet = Worksheets(Worksheets.Count).Range(cellref.Address )
End Function


"L.K." wrote:

Martin,

Thank you so much. It's great.

Lado


"Martin" wrote in message
...
Go into the VB Editor (Alt-F11) and then choose Insert, Module to place a
new
module in your workbook. Paste the following into it and then you can use
=LastSheet(A1)+LastSheet(A2) etc.

Function LastSheet(cellref) As String
LastSheet = Worksheets(Worksheets.Count).Range(cellref.Address )
End Function


"L.K." wrote:

Hi all,

I have workbook with the spreadsheets "Input", "Year 1", "Year 2", "Year
3",
.....
Workbook has different number of spreadsheets. Last spreadsheet name is
"Year 5" or "Year 6" or "Year 7" ... and it depends how many
spreadsheets
are in workbook.

On the first sheet "Input" I have formula which refers to the last
spreadsheets cells (sometimes it is "Year 7" and sometimes "Year 9" ...
and
so on).
Let this formula is:
='Year 7'!A1+'Year 7'!B1

How I can write universal formula (or macro) there instead concrete
spreadsheets names will be reference to the last spreadsheet name
(sometimes
it is "Year 6", sometimes "Year 9" and so on) of workbook.

Thank you in advance.
Best wishes,
Lado






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 718
Default Formula with the last spreadsheet of workbook

In a Module, paste following UDF:

Public Function lastSheetName() As String
Application.Volatile
lastSheetName = Worksheets(Worksheets.Count).Name
End Function

Then you can use formula:
=INDIRECT(lastsheetname()&"!A1")+INDIRECT(lastshee tname()&"!B1")

HTH
--
AP

"L.K." a écrit dans le message de
...
Hi all,

I have workbook with the spreadsheets "Input", "Year 1", "Year 2", "Year

3",
....
Workbook has different number of spreadsheets. Last spreadsheet name is
"Year 5" or "Year 6" or "Year 7" ... and it depends how many spreadsheets
are in workbook.

On the first sheet "Input" I have formula which refers to the last
spreadsheets cells (sometimes it is "Year 7" and sometimes "Year 9" ...

and
so on).
Let this formula is:
='Year 7'!A1+'Year 7'!B1

How I can write universal formula (or macro) there instead concrete
spreadsheets names will be reference to the last spreadsheet name

(sometimes
it is "Year 6", sometimes "Year 9" and so on) of workbook.

Thank you in advance.
Best wishes,
Lado






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Easiest way to expand 1 spreadsheet to a workbook of 12. Shadyhosta New Users to Excel 2 January 31st 07 07:28 PM
formula to get the spreadsheet address to print on the spreadsheet Jen Excel Discussion (Misc queries) 1 September 18th 06 01:22 PM
Spreadsheet Outline/Workbook Map Rachel, BOT Excel Programming 1 March 20th 06 07:48 PM
Is there a way to insert a formula, password or macro in an excel spreadsheet that will automatically delete the spreadsheet? oil_driller Excel Discussion (Misc queries) 1 February 8th 05 09:34 AM
Why would you need more the one spreadsheet for a workbook? Excel Excel Worksheet Functions 5 February 5th 05 12:59 AM


All times are GMT +1. The time now is 02:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"