Many moons ago, Dave Peterson created a sample Excel worksheet data entry form and kindly shared it on the Contextures website.
In Dave’s original form, users could add records on the data entry sheet, and click a button to go to the database sheet, where they could review or edit the order records.
Earlier this month, I had the pleasure of flying out of Chicago’s O’Hare airport. I was checking in at the ungodly hour of 6 AM on a Sunday, and hoped that would be a quiet time at the airport.
On the Consumerist website last week, they posted Lauren’s Excel budget template, so I downloaded it, to take a look.
I’d call it an Expense Tracker, rather than a “Budgeter”, because it’s used to record income and expenses. (Do you know the origin of the word “budget”? I had to look it up.)
Expense Tracker Formula
Here’s what it looks like, with part of the formula for the Total cell showing in the formula bar.
The grey fill colour is added with conditional formatting.
Excel Formula for Total
Shown below is the full formula for the Total.
You can see that Lauren has named the date headings (_8_10d) and hidden total row (_8_10) for each month.
Long Excel Formula for Total
So Many Named Ranges
Wow! It makes me tired just looking at that. Lauren created a lot of named ranges, to set up the file, and she’ll need to do more work to add more months.
Because there’s a separate section for each month, her formula needs a SUMIF formula for each range.
She might have to upgrade from Excel 2003, or she’ll pass the character limit for that formula.
Room for Improvement
I don’t know who Lauren is, but she should be commended for setting this up, and keeping track of her income and expenses.
Sure, there are many ways to improve her Budgeter, but it seems to work okay, even if it is a bit convoluted. At least she knows where her money is going!
What Would You Do?
But, there must be better ways to keep track of income and expenses. How would you set up an Excel workbook to do this?
I’d probably create a simple list, with columns for Date, Item, Location, Category and Amount, like the table in the screen shot below.
The last column calculates the year and month, so it’s easy to summarize by month.
add data validation to the Category column
Add Drop Down Lists
You could even get fancy, and add data validation to the Category column, with a drop down list of valid categories.
Next, enter all your budget items, then create a pivot table to summarize your spending.
Apparently you have to buy a ticket if you want to win the lottery, so I’m out of luck. However, if you’re in an office lottery pool, or buy your own tickets for the lottery, Excel can let you know if you have a winning ticket.
To keep your data details confidential, you might want to send someone a copy of a pivot table, without the link back to its source data. It’s easy to copy a pivot table, and paste it as values,but it is difficult to copy pivot table format and values.
If you’re on the second sheet, you can click the Next button to go to the third sheet.
Or, click the Back button to go to the first sheet.
Excel worksheet navigation buttons
Check for Hidden Sheets
In the comments for that blog post, Ron de Bruin suggested modifying the two navigation macros, so they test if the target sheet is hidden, before selecting it.
Finally, only 14 months later, the revised code is ready. As you know, quality work takes time! 😉
Excel Worksheet Navigation Code
Here’s the Excel VBA code for the two macros — GoSheetBack and GoSheetNext.
If the next sheet is hidden, the code keeps going until it finds the next visible sheet.
If the macro code reaches the end of the sheet tabs in either direction, it jumps to the other end, and continues from there.
'==========================
Sub GoSheetNext()
Dim wb As Workbook
Dim lSheets As Long
Dim lSheet As Long
Dim lMove As Long
Dim lNext As Long
Set wb = ActiveWorkbook
lSheets = wb.Sheets.Count
lSheet = ActiveSheet.Index
lMove = 1
With wb
For lMove = 1 To lSheets - 1
lNext = lSheet + lMove
If lNext > lSheets Then
lMove = 0
lNext = 1
lSheet = 1
End If
If .Sheets(lNext).Visible = True Then
.Sheets(lNext).Select
Exit For
End If
Next lMove
End With
End Sub
'==========================
Sub GoSheetBack()
Dim wb As Workbook
Dim lSheets As Long
Dim lSheet As Long
Dim lMove As Long
Dim lNext As Long
Set wb = ActiveWorkbook
lSheets = wb.Sheets.Count
lSheet = ActiveSheet.Index
lMove = 1
With wb
For lMove = 1 To lSheets - 1
lNext = lSheet - lMove
If lNext < 1 Then
lMove = 0
lNext = lSheets
lSheet = lSheets
End If
If .Sheets(lNext).Visible = True Then
.Sheets(lNext).Select
Exit For
End If
Next lMove
End With
End Sub
'==========================
Download the Sample File
To see the detailed instructions, and to download the sample Navigation code workbook, please go to the Excel VBA Worksheet Macro Buttons page on the Contextures website.
Watch the Excel Video
To see the steps for creating the navigation macro buttons, you can watch this Excel video.
There’s an Excel holiday dinner planner on the Contextures website, and I’ll need that in about a month, when Thanksgiving arrives. In the meantime though, there are lots of daily meals to plan.
There are instructions on my Contextures website for using a combo box with data validation cells. Click on a cell that contains a data validation list, and the combo box appears.
Last week, someone wrote and asked how to modify that code, so only a specific user could add new items. Everyone else should see a message that says they aren’t permitted to add items.
This technique isn’t foolproof, and anyone who’s determined to circumvent it would be able to. But, it’s a good way to remind people that they can’t update the list without permission.
Identify the User
One way to find out who’s trying to add a new item, is to check the user name that’s entered in the Microsoft Office application.
After you install Office, you can personalize it in Excel Options, in the Popular category, by entering your name in the User Name box.
User Name box in Excel Options
In Excel VBA, you can create variables to capture that user name, and the name of the authorized user:
Dim strAuth As String
Dim strUser As String
strAuth = "Debra Dalgleish"
strUser = Application.UserName
Block Non-Authorized Users
After you figure out who the user is, you can block them from doing something. In this workbook, we want to block all but one user from adding new items.
If strUser <> strAuth Then
MsgBox "You do not have authority to add Work Order numbers. " _
& vbCrLf _
& vbCrLf _
& "Please check with Administrator before continuing."
GoTo exitHandler
Remove the Added Item
The above code will block people from adding the new item to the data validation drop down, but doesn’t prevent them from typing the new item in the data validation cell. With another line of code, you can undo the invalid entry that they made.
Application.Undo
GoTo exitHandler
Disable Events
Because the code might make a change on the worksheet, you’ll have to turn off the EnableEvents property. That will prevent the Worksheet_Change code from running again, while it’s in the middle of running the first time.
At the top of the procedure, add the line to turn off the EnableEvents property.
Application.EnableEvents = False
In the exitHandler, remember to turn EnableEvents back on.