Beginning PivotTables in Excel 2007 will introduce you to the exciting new pivot table features in Excel 2007. Create quick summaries and pivot charts, add impact with traffic light icons, design calculated fields, group dates and numbers.

Categories

Archives

Edit Records in Excel Worksheet Data Entry Form

How can you make it easy for people to enter and edit data in Excel, but keep them away from the data storage worksheet?

Last year, I posted a Worksheet Data Entry Form in Excel, where users could enter and view Excel data. It was based on a worksheet data entry form that Dave Peterson created.

I’ve created a new version, where users can enter, view and edit the Excel data.

Version 1: Add New Records

In Dave’s original worksheet data entry form, users could add records on the data entry worksheet, and click a button to go to the database sheet, and review or edit the order records.

Excel data entry form

Version 2: View Existing Records

In version 2, I added a few buttons to Dave’s workbook, to allow users to scroll through the existing records. With the navigation buttons, you could go to the first, previous, next or last record, or type a record number, to go to a specific record.

Excel data entry form scroll

Version 3: Update Existing Records

In the latest version of the Excel Worksheet Data Entry form, I’ve added an update feature. As in the previous version, there are data validation drop down lists, to select Item and Location. The Price calculation is based on a VLOOKUP formula, and the Total formula multiplies the quantity by the price.

After you select a record, you can change its data, then click the Update button to copy those changes to the database.

Excel data entry form update

For example, in the record shown above, if you discovered that there was an error, you could change the quantity from 500 to 200. The Total formula would automatically recalculate, to show the new total of $200.00.

Then, click the Update button, and the revised quantity and total would appear in that record on the database sheet.

The Update Code

Before updating the database record, the Update code checks to see of all the data entry cells are filled in. If they aren’t, a warning message appears, and the macro stops running. This prevents you from accidentally overwriting an existing record with blank cells.

Excel data entry message

If all the data entry cells are filled in, the code:

  • writes the current date and time in the applicable row of the database
  • adds the User Name from the Excel application
  • copies the data to the database
  • clears the data entry cells

Then, with a cleared data entry sheet, you can go on to add, view and edit other records, or save and close the workbook.

Download the Sample File

The zipped sample workbook, in Excel 2003 format, can be downloaded here: Worksheet Data Entry Form

___________

Go Undercover With Hidden Excel Worksheets

hiddenAn Excel workbook certainly isn’t Fort Knox, and the information you store there isn’t too secure. If someone opens your Excel workbook, and is determined to see everything in there, they’ll probably be able to.

However, if your goal is simply to make a workbook easier for people to use, you can hide some of the worksheets, so users don’t accidentally change their contents.

For example, if your data entry worksheet has data validation drop downs, you can store the lists on a different sheet, and hide that sheet.

Hide an Excel Worksheet

To quickly hide a worksheet in Excel 2007, right-click on the sheet tab, and click Hide.

SheetHide01

If you’re using an earlier version of Excel, activate the sheet that you want to hide. Then, click the Format menu, then click Sheet, and click Hide.

SheetHide05

Show an Excel Worksheet

To show the hidden sheet again, right-click any sheet tab, then click Unhide. (In earlier versions of Excel, click the Format menu, then click Sheet, and click Unhide.)

SheetHide02

In the Unhide dialog box, click on a sheet name, and click OK.

SheetHide03

Really, Really Hide an Excel Worksheet

If you want to hide a worksheet a little better, you can use a special technique that keeps it from appearing in the Unhide list.

  • First, to open the Visual Basic Editor (VBE), press the Alt + F11 keys.
  • In the Project Explorer, at the left of the VBE window, locate your workbook.
  • In the Microsoft Excel Objects folder for your workbook, click on the sheet that you want to hide
  • If the Properties window is not showing, press the F4 key to open it
  • At the bottom of the Properties window, in the Visible property, change the setting to -2 – xlSheetVeryHidden
  • Close the VBE and return to Excel

SheetHide04

The sheet is now hidden, and its name won’t appear on the Unhide list.

Watch the Excel Hidden Sheets Video

To see the steps for hiding Excel worksheets, watch this short Excel video tutorial.

______________

Sort It Your Way With Excel Custom Lists

You know how to sort an Excel list alphabetically, and with Excel 2007 you can even sort an Excel list by colour. Did you know that you can also create a custom list in Excel and use that to sort your data, instead of sorting in alphabetical or numerical order?

Instead of sorting the products in this table alphabetically, we’ll create a custom list of products, and use it when sorting the list.

CustomSort01 

Create a Custom List in Excel

You can create a custom list in Excel by importing a list from a worksheet, or by typing a new list. In this example, there is a worksheet named Lists, and it contains a product list. We’ll import that list, to create the custom list.

CustomSort02

To create the custom list:
  1. Select the cells that contain the list items
  2. On the Ribbon, click the Office Button, then click Excel Options.
  3. In the Popular category, click Edit Custom Lists

    CustomSort03

  4. In the Custom Lists dialog box, the list address — $A$2:$A$5 — should appear in the Import range box. If not, you can click in the Import range box, and type a range, or select a range on the worksheet.

    CustomSort04

  5. To add the selected range as a custom list, click the Import button.
  6. The list items will appear in the List entries section of the Custom List dialog box, and at the end of the list of existing Custom Lists.

    CustomSort05

  7. Click OK to close the Custom Lists dialog box, and click OK to close the Excel Options window.
Use the Custom List

You can use the custom lists when sorting, and you can also use them with the AutoFill feature. Type any item from a custom list in a cell, then use the Fill handle to complete the list.

CustomSort07 

Sort the Excel List in Custom Order

To sort your list based on your custom list, follow these steps:

  1. Select a cell in the table that you want to sort.
  2. On the Ribbon’s Data tab, click Sort
  3. In the Sort dialog box, select a Column from the first drop down, and select Values from the Sort On drop down.
  4. In the Order drop down, click Custom List
  5. In the Custom List dialog box, select your custom list, and click OK

    CustomSort06

  6. Click OK to close the Sort dialog box

The list is sorted in the order of the items in your custom list.

Watch the Excel Sort Video

To see the steps for adding an Excel Custom List, then sorting by that Custom List, watch this short Excel video tutorial.


More Sort Options

After I wrote about sorting by colour, Jim Cone offered me a copy of this Special Sort Excel add-in. I finally had a chance to test it, and although I’m still not a fan of sorting by colour, the add-in has several sort options that would be useful. Instead of spending time on workarounds and formulas in helper columns, you can use the add-in. For example, you can:

  • sort a list by the length of the text in the cells
  • ignore leading articles (A, An, The)
  • sort based on the reverse order of the cell contents
  • sort by numbers at the end of the cell text

To buy the Special Sort add-in ($19 US), or request a trial version, contact Jim:  james.cone @  comcast.net

SpecialSort01 

____________

Count Cells With Specific Text in Excel

While working on a client’s sales plan last week, I had to count the orders for a couple of specific customers.  Here’s a screenshot of some sample data, with the customer names in column B.

CustomerCount01

Count cells that are an exact match

In Excel, you can use the COUNTIF function to count cells that meet a specific criterion. For example, you can use this formula to count the orders that were placed by the customer, BigMart.

  =COUNTIF($B$2:$B$14,"BigMart")

CustomerCount02 

  • The first argument, $B$2:$B$14, is the range that contains the cells to be counted.
  • The second argument, “BigMart”, is the value that we want to count.

There are 3 cells that contain the exact text, “BigMart”, so the COUNTIF formula returns 3.

Use a cell reference in COUNTIF

Instead of typing the text in the COUNTIF formula, you can refer to a cell that contains the text you want to count. For example, if cell H1 contains the customer name, BigMart, use this formula to count their orders.

  =COUNTIF($B$2:$B$14, H1)

CustomerCount03

The COUNTIF formula returns 3, the same result that you got by typing the text in the formula.

Count non-exact matches

In the sales plan data that I worked on, there were a few variations on some customer spellings, and I wanted to count all of them. In the screenshot at the start of this article, you can see that BigMart is also listed as Big-Mart and Big Mart.

Use the * wildcard

To count all the variations, you can use the wildcard character, *, to represent any characters, or no characters, in the text string. For example, if cell H1 contains the customer name with a wildcard, Big*Mart, use this formula to count all the variations.

  =COUNTIF($B$2:$B$14, H1)

CustomerCount04

The COUNTIF formula returns 7, because it counts BigMart, Big-Mart and Big Mart.

Use the ? wildcard

If you use the ? wildcard character instead of the * wildcard character, it represents one character.

CustomerCount05

Now the COUNTIF formula returns 4, because it counts Big-Mart and Big Mart, but not BigMart. It doesn’t count BigMart, because there isn’t a character between the g and the M.

More COUNTIF Examples

For a few more examples of counting cells with specific text, you can visit the Excel Count Functions page on the Contextures website.

_______________

Plan Your Party Seating with Excel

If you’re having a party this weekend, you can use Excel to plan the guest seating. And if you sent me an invitation, it hasn’t arrived yet!

In this example, you’ll enter the guest names on an Excel worksheet, then fill the tables by selecting names from data validation drop down lists. After you’ve selected a name, it will disappear from the drop down lists, so you can’t accidentally assign one of the guests to two different seats.

SeatPlan01

 

Enter the Guest Names

On a worksheet named Lists, the guest names are typed in column B. Sort the names in alphabetical order, so the names will be easier to find in the data validation drop down lists.

SeatPlan02

Draw the Tables and Chairs

On a sheet named TablePlan, use the Excel drawing tools to create the tables and chairs. I used the Oval shape to draw 3 tables, with 8 chairs at each table.

Tip: To draw a circle, hold the Shift key while you use the Oval shape drawing tool.

SeatPlan03

You can number and colour code the tables, to make it easier to keep track of things.

List the Tables and Seats

To the left of the table diagram, create a list of the tables and seat numbers. If you colour coded the tables, use the same colours in the table list.

In the next column, format the cells where you’ll select the guest names. You’ll add data validation to those cells later.

SeatPlan04

Add a Formula to the Guest List

On the Lists worksheet, you’ll add a formula to check if the name in that row has been assigned a seat. The first name is in cell B1, so enter this formula in cell C1:

=IF(COUNTIF(TablePlan!$D$2:$D$25,B1),"",ROW())

Copy the formula down to the last name.

If a guest has been assigned to a seat, their name will appear in column D on the TablePlan sheet. In that case, this formula will return an empty string. If a seat hasn’t been assigned, the formula will return the row number.

Create the List of Unassigned Guests

In column D, you’ll add an array formula to list the unassigned names. This list will be used for the data validation drop down lists.

In this example, cells D1:D24 are selected, and this formula is array entered (press Ctrl+Shift+Enter)

=IF(ROW(B1:B24)-ROW(B1)+1>COUNT(C1:C24),"",
        INDEX(B:B,SMALL(C1:C24,ROW(INDIRECT("1:"&ROWS(B1:B24))))))

This is a multi-cell array formula (by DanielM.) that moves blank cells to the bottom of the list. For more information on this formula, see Excel Data Validation – Hide Previously Used Items.

In the screenshot below, some of the guest have been assigned to seats, and their names don’t appear in column D.

SeatPlan05

Define a Named Range

Next, you’ll create a dynamic named range for the unassigned guests lists.

  1. On the Excel Ribbon, click the Formulas tab
  2. Click Define Name
  3. In the New Name dialog box, type NameCheck as the name
  4. In the Refers to box, type this OFFSET formula, then click OK

=OFFSET(Lists!$D$1,0,0,COUNTA(Lists!$D$1:$D$24)
      -COUNTBLANK(Lists!$D$1:$D$24),1)

SeatPlan06

Add the Data Validation Drop Down Lists

Next, you’ll add the drop down lists:

  1. On the TablePlan sheet, select the cells for Guest names, cells D2:D25 in this example.
  2. On the Excel Ribbon, click the Data tab
  3. Click Data Validation
  4. In the Data Validation dialog box, from the Allow drop down, select List
  5. In the Source box, type:  =NameCheck
  6. Click OK

SeatPlan07

The drop down lists are added to the cells, and you can select a guest name.

Link the Seats to the Guests

To show the guest names on the assigned seats, you can link the shapes to the cells.

  1. Click on the shape for Seat 1 at Table 1.
  2. Click in the Formula Bar
  3. Type an equal sign, then click on the guest list, where the Table 1 Seat 1 name will be entered
  4. Press Enter to complete the link

SeatPlan08

Repeat these steps to link all the seats to the guest link cells.

Assign the Guest Seats

Now you can select guest names from the drop down lists on the TablePlan sheet, and get your party organized. Keep all those arguing relatives at separate tables, and everything should go well.

Download the Sample File

If you’re planning your own party, you can download the sample file with an Excel seating arrangement example.

__________

Running Totals Are Easy With Excel Pivot Tables

This week I’m working on a client’s sales plans for the upcoming fiscal year. They forecast sales per month by product and customer, and we use some pretty complicated formulas to sort things out. Of course, anywhere that it makes sense to use a pivot table, I create one. It’s a great way to summarize all the details, and review the overall totals.

For example, on a worksheet you can use formulas to create a running total, but in a pivot table it’s much easier  — you can quickly create running totals with a couple of mouse clicks.

Let’s take a look at a pivot table based on some faked sales data. In the screen shot below, you can see the total sales per region per month, and the Grand Total per month. By changing the Sales field settings, you can show a running total, instead of the normal Sum.

PivotRunningTotal01

Add the Running Total

To change the sales field, and show a running total, follow these steps:

  1. In the pivot table, right-click one of the Sales amount cells.
  2. In the context menu that appears, click Summarize Data By
  3. Click More Options

    PivotRunningTotal02

  4. In the Value Field Settings dialog box, click the Show Values As tab
  5. From the Show Values As dropdown list, select Running Total In.
  6. Select the Base Field where you want to see the running total. In this example, we’d like to see the running total down the list of dates, so OrderDate is selected as the Base Field.

    PivotRunningTotal04

  7. Click OK, to close the Value Field Settings dialog box.

The pivot table changes, to show the running total for sales.

In the following screenshot, you can see the running totals in column C, and the original monthly totals in column H. Each month’s total sales is added to the previous total, to show the running total.

PivotRunningTotal05

Change the Running Total Base Field

The most common use for running totals is to show amounts accumulated over time, as in the sales by month example above. However, you can use a non-date field as the base field for a running total. For example, in an election, you could show a running total of votes as each district submits its results. Or, for a large construction project, you could show a running total of expenses over the project phases.

In this pivot table, I’ve added City to the Column area, and used that as the Base Field for the running total.

PivotRunningTotal06  

Now, instead of the running total going down the pivot table by month, it goes across the pivot table, by city.

Be careful though — if you use a Base Field that isn’t in the pivot table layout, you’ll see #N/A for all the running total values.

PivotRunningTotal07

Running Totals in Excel 2003 Pivot Tables

The running total technique is similar in Excel 2003 pivot table, and you can see the instructions here: Excel 2003 Pivot Table Running Totals. It also shows the results when there are multiple fields in the row area, and a running total is added to one of those fields.

Watch the Running Totals Video

To see the steps for creating running totals in Excel 2003, please watch this short Pivot Table Running Totals video.

__________

Back In Time With Microsoft Excel

A very nice email, from someone who visited the Contextures website, made me think about how long I’ve been using Excel. My guess was that I’d started around 1987, so I fired up the old Mac laptop, and dug some old floppies out of the storage cupboard.

ExcelMac01

The laptop is a Mac PowerBook 170, from late 1991, and it’s running the Mac version of Excel 3.0. There’s a Mac 128K model in the back room too, but I didn’t have the strength to dig that out. (I hope the producers of the tv series, The Hoarders, don’t call me now.)

As you can see, the application files were much smaller in Excel 3.0. Of course, that still took a good chunk out of my 40MB hard drive.

ExcelMac02

Flashy Excel Charts

Even though the machine didn’t have colour, I was still able to make some pretty flashy 3-D charts in the old days. I have no idea what this was supposed to show, but maybe it was the results of an Olympic ski jumping event.

ExcelMac03

I’m sure that I never wasted any time playing TETRIS, when I was supposed to be working on Excel files.

ExcelMac04

Sorting a List

Way back then (and until Excel 2007), we were only able to sort by 3 levels, and we couldn’t sort by colour. That didn’t matter much to me, since I didn’t have colour!

ExcelMac05

My Oldest Excel File

There may be something older on a floppy disk at the back of the storage cupboard, but I finally found an Excel file that I’d worked on in April 1987. I was creating some Excel training files, to be used by Apple vendors.

ExcelMac06

The Excel 3.0 File and Excel Toolbar

Here’s what the file looked like, and it’s interesting to see the minimalist toolbar too. Do you remember what all those icons were for?

ExcelMac07

How Long Have You Used Excel?

There’s an Excel poll on my Debra D blog, so if you have a minute, please go and answer the question – How Long Have You Been Using Excel?

It’s About Time

When I was thinking of a title for this blog post, a really old (and really bad) tv series popped into my head – It’s About Time. The show was about two astronauts who accidentally break the time barrier, and go back to prehistoric days, where they live with a cave family. In a strange coincidence, Wikipedia says that one of the astronauts in It’s About Time was named Mac. By the way, they changed Imogene Coca’s character name to Shadd, after the pilot episode.

The series was by the creator of Gilligan’s Island, and used sets, props and music from that series. Here’s a clip from YouTube that shows the opening and closing credits and theme song. Please don’t blame me if the song gets stuck in your head.

____________

Collect Data From Users in Excel VBA

You can use Excel VBA to show messages to someone who’s using your workbook. This messages lets the user know that a customer name must be selected, and there’s an OK button to click after reading the message. (No one would ever click the OK button without reading the message, would they?)

CustMsg06

But sometimes you want to get information from a user, instead of giving it. Let’s look at a couple of ways to do that, in Excel VBA.

Add Buttons to an Excel Message Box

The message box that’s shown above appears if someone tries to print an order form, and a customer name hasn’t been selected. Here’s the code that we created in the previous blog post on using Excel VBA to show messages.

VBEBeforePrint05

A message box can return information to Excel VBA, as well as give information to the user. Instead of a single OK button on the message box, you could show Yes and No buttons. Perhaps the user needs to print an order form occasionally, without a customer name.

We’ll change the message text, to ask, “Print without Customer Name?” and we’ll change the message box style from vbCritical to vbYesNo.

ExcelVBAInput01

Now, if you try to print with no customer name, the message box shows the Yes and No buttons, with the new text.

ExcelVBAInput02

Change the Button Behaviour

With the new message box code, we have two buttons, but it doesn’t matter which one you click – the printing is still cancelled. We’d like to change the code so that if you click No, the printing is cancelled, and if you click Yes, the order form is printed.

When someone clicks a button in a message box, it returns a numeric value. There’s a list in the Excel VBA Help that shows the value returned by each button.

ExcelVBAInput03

So, if someone clicks the Yes button, it returns a numeric value of 6. We’ll change the code to capture this.

  1. We’ll add a variable, lRsp, to the code, to store the returned value.
  2. At the start of the MsgBox line, add the lRsp variable, and enclose the MsgBox arguments in brackets.
  3. Add an If…End If statement, to cancel the printing if the returned value is not equal to 6.

ExcelVBAInput04

Download the Sample File

To see the order form and the completed Excel VBA code, you can download the Excel order form. Enable macros when the file opens.

Use an Excel UserForm

If you need to collect more than a Yes or No response from your users, you can use an Excel UserForm. There are written instructions and video tutorials here: Excel UserForm With ComboBoxes 

_______________

Sort By Colour in Excel

In the old days, the Sort dialog box in Excel only had 3 levels. However, with a bit of planning, you could sort Excel data by 4 columns or more, and once you learned that trick, life was good. Or at least it was sort of good. ;-)

Sort03

In Excel 2007, the Sort dialog box is much fancier, and you can include up to 64 sorting levels. I’ve never needed anywhere near that many – 5 or 6 fields is plenty for most tables that I’ve had to sort.

Sort By Colour

Another new feature in Excel 2007 is the ability to sort by cell or font colour, or by cell icon.

SortColour01

If you have different colours in a column, you can choose one to show up at the top or bottom of a sorted list.

SortColour02

If you used conditional formatting to add cell icons, such as traffic lights, you can sort by those icons.

SortColour06

To put the colours or cell icons in a specific order, you can add the same field multiple times in the Sort dialog box, and choose a different colour or cell icon for each sorting level. This won’t be too difficult if you have only a few colours in the list, but will be more challenging if you have lots of colours.

SortColour03

The list on my worksheet, that was previously sorted by date, is now sorted by the colours, in the order that I selected above. Yellow isn’t in the Sort level specifications, so it appears at the bottom of the list.

SortColour04

Sort By Colour At Your Own Risk

Even though you can sort by colour now, I wouldn’t recommend it. I’ve seen too many rainbow coloured Excel worksheets, where nobody can remember what the colours mean. Is yellow good? Is blue bad? Is there a colour code somewhere?

I’d rather add another column in the worksheet, and put a number code or text comment there. So, instead of marking the overdue accounts with a red fill colour, type “Overdue” in another column, or use a formula to calculate which accounts are overdue.

Or, instead of highlighting the customer names that you want to send an email to, type an X in an Email column. Then, you can sort or filter the Overdue accounts or the Email column, to focus on the rows of interest.

SortColour05

Do You Sort By Colour?

Maybe I’m missing something, and the feature is working well for you. Some people must have asked for the feature, since they added it to Excel 2007.

In your Excel worksheets, do you ever sort by colour? In what kind of lists or situations is it most helpful for you?

_______________

More Room to Work in Excel 2007

You might not love the Ribbon in Excel 2007, but the user interface does have new features that are an improvement over Excel 2003. The new features are useful when you’re working with large formulas or long names.

Change the Formula Bar Height

In Excel 2003, if you click on a cell that contains a long formula, it can spill onto the worksheet, hiding the column headings. It’s nice to see the formula, if you want to edit it, but annoying if you’re trying to do something else.

LongFormula01

In Excel 2007, you can adjust the height of the formula bar, and the long formulas don’t cover the worksheet. To adjust the height:

  1. Point to the bar at the bottom of the formula bar.
  2. When the pointer changes to a two headed arrow, drag up or down, to change the formula bar height

FormulaBarHeight01

After you’ve adjusted the height, you can quickly restore it to its previous height, by clicking the Collapse Formula Bar button.

FormulaBarHeight03

When the formula is collapsed, the button changes to Expand Formula Bar. Click that to return to the previous height setting.

FormulaBarHeight04

Also, if the formula is too long to show in the formula bar at its current height, scroll buttons appear, as you can see in the screen shot above. You can click the scroll buttons to view the formula, if you don’t want to change the formula bar height.

Widen the Name Box

Another new feature that I find really helpful is the ability to widen the Name Box. Instead of just seeing the start of a long name, and three dots, you can widen the Name Box to see the entire name.

To adjust the Name Box width, point to the dividing line at the right edge of the Name Box, and drag to the right.

FormulaBarHeight05

To return to the default Name Box width, double-click the dividing line. (At least I think it’s the default width – I’ve changed my settings too many times to remember exactly.)

Excel’s Help says, “The maximum width of the name box is half of the width of the worksheet.” However, I’m able to widen the Name Box to the full width of the worksheet, and narrow it to nothing. Maybe that restriction applied in the Beta version, and the Help wasn’t changed.

Do You Use These Features?

I’ve used Excel for so many years without these features, that I often forget they’re available. Long formulas can be hidden in the formula bar when condensed, because they don’t spill onto the worksheet, the way they used to. If a formula is cut off in a logical place, you might not even realize that part of it is hidden. Those scroll buttons are very subtle, and are the only clue that a formula doesn’t fit.

Do you remember to use the new sizing features? Do you prefer them to the Excel static settings?

Watch the Video

Here’s a short video that shows the new features for adjusting the formula bar height and the Name Box width. It also shows how to temporarily collapse the Ribbon, so only the tabs are visible. That gives you an extra inch of space, if you need it when working on a large worksheet.

_______________