Puzzle ?

Franz

Board Regular
Joined
Aug 12, 2002
Messages
90
I have a worksheet ("master") with a macro that allows a user to make many cloaned worksheets (but renamed) within the same workbook. I want to take the same cell value(N4)on each new worksheet and use a formula on the "master" to obtain a SUM of all the N4 values.

The problem is I will never know how many cloans were created and what the user named them. Can this be done or am I asking to much?

Thanks for anyone who can help!
See my other post "Copy and Rename Worksheets"
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
hi Franz

one possible solution would be to place blank 'dummy' sheets as the beginning and ending sheets in your workbook - you could call them 'first' and 'last' or something along those lines - then you could have a formula like this:

=SUM(first:last!N4)

which would sum the values in cell N4 in all sheets located between the 'first' sheet and the 'last' sheet, regardless of how many sheets there are or what you name them. would this work for you?

hth
kevin
 
Upvote 0
This would probably work fairly well as long as the user does not play around with the sheet tabs.I would need a macro to insert a blank sheet called "end" as the last worksheet in the series and at the same time place the SUM formula in a cell on the first worksheet which will be called "Estimate". Can you help?Thanks.
 
Upvote 0
hi franz

i came up with a different idea using vba so that you would not have to insert any blank sheets:

Code:
Sub sumallsheets()
lastwks = Worksheets.Count
firstsheet = Worksheets(1).Name
lastsheet = Worksheets(lastwks).Name
[a1].Value = "=sum(" & firstsheet & ":" & lastsheet & "!N4)"
End Sub

in this code, 'lastwks' equals the total number of worksheets in the workbook,
'firstsheet' is the name of the first worksheet, and last sheet is the name of the last worksheet. then this code creates a formula in cell A1 of the active sheet that totals the amounts in cell N4 of all your sheets. using this, you do not have to insert any dummy sheets at the beginning or end of your worksheet tabs, and it will continue to work as you add more sheets to your workbook, regardless of what sheet names you use, or in what order you put them. modify this code to suit you own needs. would this work better for you?

hth
kevin
 
Upvote 0
Kevin,

This is a most excellent solution and takes out the "user" error factor. Thank you for getting back to me with this code.

Kind Regards
 
Upvote 0
Kevin,

Hmmm, I've been thinking and was wondering what is the syntax to have the "SumAllSheets" code disabled when the user creates a copy of the worksheet that contains say a command button for the macro.

This way I can have the code only work on one main worksheet.Currently I have the user create a copy of the worksheet in question by pressing a command button. Thanks in advance.
 
Upvote 0
if you want the code to only work in one particular sheet, then modify your code as follows:

Code:
Sub sumallsheets()
lastwks = Worksheets.Count
firstsheet = Worksheets(1).Name
lastsheet = Worksheets(lastwks).Name
If ActiveSheet.Name<> "Sheet1" Then Exit Sub
[a1].Value = "=sum(" & firstsheet & ":" & lastsheet & "!N4)"
End Sub

(EDITED CODE)

where "Sheet1" is the name of the sheet you want this code to work in - it will not work in any of the other sheets. modify to suit your needs

hth
kevin
This message was edited by kskinne on 2002-11-19 16:17
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,942
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top