Save Time When Saving Excel Files

Last week, Seth Godin recommended hiring a geek to help you save an hour a day.

Well, you’re a geek, so you don’t have to hire one! Just pay attention as you run through your morning office routine, and answer this question:

  • What can you change about your Excel habits, to save an hour a day, or even a few minutes?

Then, make the change.

Doing Steps Manually

Every morning, I follow these steps:

  • download some website statistics to Excel,
  • crunch the numbers, and
  • save the raw data file.

Fortunately, I have a macro that does the first 2 steps. For some reason, I was doing the last step manually. Don’t ask me why.

Excel is a bit slow when opening the Save As dialog box, so that final step was taking 30-60 seconds. Not a huge productivity drain, but why do something manually, if it can be easily automated?

Make It Automated

To get rid of that manual step, I added a few lines of code to the existing macro. The Excel VBA code saves a copy of the active workbook, into the Backup folder, and adds the previous day’s date to the file name.

It only took me a couple of minutes to add the code, so the time invested was quickly repaid. Now I just have another 59 minutes to trim!

Macro Code to Save Daily File

'------
Sub SaveDailyData()
Dim wbData As Workbook
Dim strDir As String
Dim strName As String
Dim strExt As String
Set wbData = ActiveWorkbook
strDir = "C:\Backups"
strName = "DailyData_" & Format(Date - 1, "yyyymmdd")
strExt = ".xls"
wbData.SaveCopyAs strDir & strName & strExt
wbData.Close SaveChanges:=False
End Sub
Save Time With Excel Macros
Save Time With Excel Macros

___________

Excel CONVERT Function Made Easy

Do you ever use the Excel CONVERT function? Or, do you avoid that function, because you can’t remember all the measurement unit codes?

For example, the formula =CONVERT(10,”klt”,”gal”) will convert 10 kilolitres to 2,641.7205 gallons – if you get those codes right.

You might be able to remember lt and gal, but probably not many of the other codes.

Continue reading “Excel CONVERT Function Made Easy”

Move ListBox Items In Excel UserForm

Last week, we saw how to move items from one listbox to another on an Excel worksheet.

Now I’ve added a page on the Contextures website, with similar instructions for listboxes on an Excel UserForm.

Thanks to Dave Peterson, who provided both sets of sample code.

ListBoxes in Excel UserForm

In the screen shot below, there is an Excel UserForm with two ListBoxes, and four command buttons, down the centre.

  • The buttons with 2 arrows move ALL items from one list to the other, in the direction that the arrows are pointing
  • The buttons with 1 arrow move the SELECTED items from one list to the other, in the direction that the arrow is pointing
Excel UserForm with two ListBoxes
Excel UserForm with two ListBoxes

Download the Move Listbox Items Sample File

To see the code, and test the ListBox move items code for a UserForm, you can download the ListBox UserForm Move Items sample workbook.

The file is in Excel 2007 format, and is zipped. It contains macros, so enable them if you want to test the code.

Related Excel VBA Tutorials

If you’re looking for a fun and exciting way to fill your holiday Monday, here are links to a few other UserForm and Excel VBA tutorials on my Contextures website:

FAQs, Excel VBA, Excel Macros

Create an Excel UserForm Video

UserForm with ComboBoxes

Excel VBA Edit Your Recorded Macro

Excel VBA Getting Started

______________________

Move Excel Listbox Items

To select specific items from a long list, you can create 2 ListBoxes on a worksheet.

Then, use arrow buttons to move all the items from one list to the other, or move selected items only.

ListBoxes on Worksheet

In the screen shot below, there are 2 ListBoxes, and 4 buttons with arrows, on a worksheet named CreateRpt.

  • In the ListBox at the left, you can select one or more items that you’d like in a report.
  • Then, click the 2nd button, with one arrow that point to the right.
  • The selected items will move to the ListBox on the right.

OR

  • You could click the. top button, to move all the items to the right-hand ListBox.
Two ListBoxes and Buttons on Worksheet
Two ListBoxes and Buttons on Worksheet

Items List on Worksheet

When you get started, the list at the left is filled with items. Those items come from a named range, on a worksheet named Admin.

You could modify that list, to include the items that you need in your ListBox.

Item list in named range on Admin worksheet
Item list in named range on Admin worksheet

Use the ListBoxes

In the sample file that you can download, there is a Menu worksheet, with a navigation button, “Select Report Items”.

Click that button to go to the CreateRpt worksheet, where the ListBoxes are located.

Navigation button on Menu sheet
Navigation button on Menu sheet

Macro Runs Automatically

When the CreateRpt sheet is activated, an event procedure (macro) runs automatically.

The VBA code in that event procedure does the following steps:

  • Clears both ListBoxes
  • Adds all items from worksheet list, in ListBox at the left

Back to Menu Sheet

On the CreateRpt sheet, there is another navigation button, “Menu”, at the top left of the sheet.

Click that button, and a macro runs, to take you back to the Menu sheet.

Navigation Button Macros

The two navigation buttons run simple macros, and the VBA code is shown below.

First, here is the code that the Menu button runs:

Sub GoMenu()
Worksheets("Menu").Activate
End Sub

Next, here is the code that the Select Report Items button runs:

Sub GoRpt()
Worksheets("CreateRpt").Activate
End Sub

Read the Detailed Instructions

Thanks to Dave Peterson, who sent me the instructions and sample code for moving listbox items.

To see the details on how this technique works, visit the Excel VBA Move Listbox Items page on the Contextures website.

The tutorial shows, step by step,  how to set up the worksheets, add the ListBoxes, and create the named ranges.

It also shows all of Dave’s sample code, for moving the items between the ListBoxes.

Download the Move Listbox Items Sample File

To see the code, and test the Listbox move items code, you can download the Listbox Move Items sample workbook.

The file is in Excel 2007 format, and is zipped. It contains macros, so enable them if you want to test the code.

Video: Move Listbox Items on Worksheet

To see the steps to create the Listbox example, you can watch this Excel video tutorial.

______________

Quickly Find Excel Ribbon Commands

If you have been using the Ribbon in Excel 2007 or Excel 2010 for a while, you can probably find most of the commands that you need. It’s those infrequently used commands that cause the problems. You knew where they were on the old menu bar, but where the heck are they on the Ribbon?

[Update: This Microsoft download is no longer available]

The Office Labs people at Microsoft have taken pity on our poor, fumbling fingers, and come up with a solution – the Search Commands add-in. This free tool lets you type the name of a command, and magically find it. Think of all the time that you’ll save!

For now, at least, the add-in is only available in English, and works in Word, Excel and PowerPoint. It requires Windows XP, or later, operating system.

Download the Search Commands Add-In

To install the Search Commands add-in, go to the download page on the  Microsoft site.

Optional – Click on the plus signs, to see

  • Details
  • System Requirements
  • Install Instructions

Then, click on the Download button, to get the file. Next, run the downloaded file, to install the add-in.

Search for Commands

After you run the setup program, to install the add-in, a Search Commands tab automatically appears on the Ribbon.

searchcommand02

  • In the Search box, at the left end of the Ribbon, type the name of the command that you want to use. For example, if you can’t find the command to protect the worksheet, type “Protect” or “Protect Sheet”.
  • Click the magnifying glass symbol, to start the search
  • One or more commands that match your search term will appear in the search results section, to the right of the search box.

searchcommand03

If there are several commands that match your search words, you might need to use the Previous and Next buttons to scroll through the list of commands.

For example, if you type “Protect”, instead of “Protect Sheet”, there are 16 commands found, shown on 2 pages.

searchcommand04

Use the Search Results

If the search results include the command that you were looking for, just click on it, to run that command. Quick and easy!

And to find out where that command lives on the Ribbon, point to the command, before you click it. The popup description shows the location of the command, by listing the Tab, command group, and command name.

searchcommand05

It’s funny – I didn’t realize that the Protect Sheet command was also on the Home tab. I expected it to point to the command on the Review tab. It must look for the first instance of the command in the Ribbon tabs.

Also, the location description doesn’t mention that you have to click the Format command, to see the Protect Sheet command, so you might need to do a bit of searching, to find the exact location.

searchcommand06

Commands Not in the Ribbon

Another nice feature of the Search Commands add-in is that it even finds some commands that aren’t in the Ribbon.

For example, if you type Pivot, it shows the PivotTable and PivotChart Wizard command.

searchcommand07

Room for Improvement

The Search Commands add-in is a work in progress, so it’s not perfect yet.

  • It should have full descriptions of the location, as mentioned in the Protect Sheet example above.
  • The Search Commands tab doesn’t shrink, when you make the Excel window narrower, like other tabs do.
  • Include settings that are in the Excel Options window, like hiding zeros on the worksheet, or changing to R1C1 Reference Style.

What features would you like to see in the add-in?

Customize Excel Ribbon Tab

You can also customize the Excel Ribbon, by moving or removing the groups on a default Ribbon tab. In this video, see how to move groups on the Data tab, so the tools that are used most often are in the middle of the tab, and easier to reach.

Related Articles

Excel Ribbon — Getting Started

Excel Ribbon – Custom Tab

__________________

Last Row Incorrect With Excel Table

When you’re working with Excel VBA, you might want find the last row with data, so you can paste new data in the row below that.

The following code works up from the last row on the worksheet, until it hits a cell with data. It’s like using the End key and Up arrow, to manually move from the bottom of the worksheet.

Sub GetLastRow()
Dim ws As Worksheet
Dim lRow As Long
Set ws = ActiveSheet
lRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
MsgBox lRow
End Sub

In the sample sheet, the last data in column A is in row 10, and that’s the result when running the code.

lastrowtable01

Unexpected Result

This week, I was using similar code in a client’s workbook, to find the last row of data. The data was in a named Excel table, and the last couple of rows in the table were blank. I wanted to find the last row with data, so I could change the table definition, to end at that last row.

When I used the same Excel VBA code, the last row wasn’t what I expected – it found the last row in the named table, even though that row was empty.

lastrowtable02

I’m sure that information is helpful in some situations, but it sure wasn’t going to help me resize the table!

My Last Row Workaround

There might be a more sophisticated solution to this problem, but I added a line of code to resize the table, so it ends at row 2.

Then, the code found the correct last row of data, and resize the table to end at that row.

Sub ResizeTheTable()
Dim ws As Worksheet
Dim lRow As Long
Set ws = ActiveSheet
ws.ListObjects(1).Resize ws.Range("$A$1:$H$2")
lRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
ws.ListObjects(1).Resize ws.Range("$A$1:$H$" & lRow)
MsgBox lRow
End Sub

That fixed the problem, and the table resized correctly.

lastrowtable03

A Better Solution?

Have you run into this problem with named Excel tables? How did you solve it?

Video: Create an Excel Named Table

When you work with lists in Excel, use the built-in Table feature, to make it easy to sort and filter your data. This short video shows the simple steps


____________