Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Excel 2003: I'm building a "Cost Sheet" that will use a different tab for each day of the month. Each Daily Tab will import total from the preceeding days tab.
Any easy way to create this?
Thanks in advance...

re: Any easy way to create this?
Create what? A workbook with 31 tabs? Or the functions required to import totals from previous day's tab?
The following code will create a workbook with 31 tabs, named Day 1 - Day 31. As far as the other question, you'll need to be a lot more specific.
Note: This code will rename the existing sheets in a workbook (new or old) to Day 1, Day 2, etc. and then add enough sheets to get you to Day 31, all named appropriately.
Sub DailyTabs()
'Rename Existing Sheets
For Shts = 1 To ActiveWorkbook.Sheets.Count
ActiveWorkbook.Sheets(Shts).Name = "Day " & Shts
Next
'Add more sheets and rename them
For NewSht = ActiveWorkbook.Sheets.Count + 1 To 31
ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
ActiveWorkbook.Sheets(NewSht).Name = "Day " & NewSht
Next
End Sub

Thanks! I can see that you are far advanced in Excel.
The code you kindly provided... Where do I apply this data to create these tabs?
Lastly, the tabed worksheets will import the previous day's "Total Costs" column into the next day's "Previous Costs" column.
Thanks again for helping this poor old rookie out! I work offshore in the Gulf of Mexico and I'm sort of stuck for finding a good Excel source of education.
1sgparker@gmail.com

Part 1 of 2: Creating the Tabs in a workbook -
To use the code to create a workbook with 31 tabs, do the following:
Select all the code above, including everything from Sub DailyTabs() to End Sub
Open a new workbook. Click on Tools...Macro...Visual Basic Editor.
This should open a window where you can paste the code into. If it doesn't, Click on Insert...Module.
Paste the code in the window and either click Run...Run Sub/UserForm, or click the little green arrow in the toolbar or hit F5.
Note: if you run this in a existing book that has data in it, I suggest you create a backup copy first in case something goes terribly wrong.
Your workbook with 31 tabs should be created.

Part 2 of 2 - Creating the formula to pick up the previous day's totals.
(This took a bit of research and trial and error, but I think it does what you want.)
1 - In your 31 tab workbook, click on Insert...Name...Define
2 - In the Names In Workbook field enter something like PrevDayTotal or anything other name that you will remember.
3 - In the Refers to field, paste this formula:
=INDIRECT(INDEX(GET.WORKBOOK(1),GET.DOCUMENT(87)-1)&"!"&ADDRESS(ROW(),3))Note: the 3 near the end represents the column number that holds the Total Costs in each sheet (I assume it's the same for each day) In this case I choose Column C (3). You should change that value to match your column.
4 - Select the tab for Day 2, hold down the shift key and select the tab for Day 31. This should highlight all the tabs, which means that whatever you do in one sheet, you will do to every selected sheet.
5 - In the first cell where you want the previous day's value, enter =PrevDayTotal or whatever name you chose for this function.
6 - Drag the "formula" down as many rows as required to pick up all the values from the previous sheet.
What should happen is that the PrevDayTotal function will look back 1 sheet and return the value in the same row and whatever column you used in the "Refers to" field.
Let me know if this works for you.

Hold on, we have an issue!
This portion of the formula I offered has a problem: GET.DOCUMENT(87)-1
It returns a #REF error if the sheet names have a space in them. It also fails when there is a -, and a few other characters. I don't quite know why.
Anyway, the solution is to name your sheets Day1 or Day_1 or something like that. If you get the #REF error, it's mostly because you used a character in the sheet name that the formula doesn't like.
If you change the orginal code to read as follows, it will create tabs that like Day_1 and everything should be fine.
Sub DailyTabs()
'Rename Existing Sheets
For Shts = 1 To ActiveWorkbook.Sheets.Count
ActiveWorkbook.Sheets(Shts).Name = "Day_" & Shts
Next
'Add more sheets and rename them
For NewSht = ActiveWorkbook.Sheets.Count + 1 To 31
ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
ActiveWorkbook.Sheets(NewSht).Name = "Day_" & NewSht
Next
End SubSorry about that, I didn't test both parts of my suggestions as a "complete package". Now I need to go off and find out why you can't have a space or - in the sheet name.

Part 1 - Success! I can figure out how to modify the VBE code if necessary. I'll likely just call each day 1, 2, 3, etc.
The cell addresses I am trying to import from the "Previous Day" is H13:H105. I bet that makes this easier.

Not sure how H13 - H105 makes anything "easier".
If the goal of this exercise was to find an easy way populate all 31 sheets with the formulae, then my suggestion of using a Defined Name still fits the bill. Simply change the 3 to an 8, and it will pull values from column H instead of C.
Meanwhile, I'm working on a solution that will allow you to use any sheet name.

OK, I needed some help from an expert on this one. We don't know exactly why my original suggestion fails with certain sheet names (such as sheet names with spaces) but we're pretty sure this one will work for any valid sheet name.
Follow the same procedure to create a named range:
1 - Insert...Name...Define
2 - Enter some text in the Names box
3 - Paste this into the Refers to: box
4 - Click OK=INDIRECT("'"&MID(INDEX(GET.WORKBOOK(1),GET.DOCUMENT(87)-1),FIND("]",INDEX(GET.WORKBOOK(1),GET.DOCUMENT(87)-1))+1,255)&"'!"&ADDRESS(ROW(),3))
Enjoy!

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |