Keyboard Metrics III

In the grand tradition of Keyboard Shortcut Metrics and More Keyboard Metrics, here’s this:

Procedure 2016 2017 2018 Grand Total
MakeComma 20.54% 18.67% 19.01% 19.19%
WrapSheetsDown 13.80% 17.15% 9.93% 14.93%
WrapSheetsUp 8.60% 15.36% 7.33% 12.16%
FillVirtualScreen 10.50% 11.04% 8.42% 10.40%
CopyPasteValues 14.00% 4.84% 2.20% 6.54%
ShowFormatting 5.85% 5.13% 7.04% 5.68%
IncrementDate 4.25% 4.08% 9.77% 5.23%
MarkYellow 4.55% 5.44% 5.29% 5.20%
SelectAdjacentCol 4.87% 4.71% 6.19% 5.04%
DecrementDate 3.56% 1.87% 11.93% 4.24%
GetMappedAddress 2.39% 2.21% 2.73% 2.35%
FrozenHome 2.26% 2.39% 2.32% 2.34%
MakeTable 0.00% 1.80% 4.07% 1.81%
ChangeSign 2.03% 1.35% 0.77% 1.40%
FillSeries 0.49% 1.38% 1.99% 1.28%
CopySum 2.22% 1.18% 0.33% 1.27%
ConvertColumnToText 0.00% 0.63% 0.00% 0.36%
SelectPrecedents 0.00% 0.46% 0.12% 0.29%
SwitchAggregate 0.00% 0.24% 0.49% 0.23%
MatchColumnWidths 0.10% 0.06% 0.08% 0.07%
Grand Total 100.00% 100.00% 100.00% 100.00%

Look at DecrementDate making a charge.

Incrementing Months and Years

As you know, I love keyboard shortcuts. But I hate entering dates. So I created this little helper. In my new accounting system, they also have shortcut keys for incrementing weeks, months, and years. I don’t have much use for incrementing weeks, but I could kick myself for not thinking of the others. Plus Alt+semi-colon is just sitting there doing nothing.

International Keyboard Shortcut Day 2018

The first Wednesday of every November is International Keyboard Shortcut Day. Today people from all over the world will become far less efficient for short time in an effort to be far more efficient the rest of the year.

The end of inefficiencies. Am I right?

To celebrate this year, I took my wall calendar off my wall and I’ll use Win+Alt+D to view the Windows calendar. My usual method to see an electronic calendar is to Alt+Tab to Outlook and Ctrl+2 to switch to the calendar (Ctrl+1 switches you back to the inbox (or wherever you were in Mail)). I also might Win+1 to get there because Outlook is the first icon on my taskbar. That’s less desirable, though, because Outlook doesn’t always play nice. Sometimes it’s not on month view and it’s a pain to get it to look like I want. So I’ll try out my new found Win+Alt+D to use the built-in Windows calendar.

If you just want to get your feet wet, head over to True Insights and download the The Ultimate Excel 2016 Keyboard Shortcut List. It’s an Excel workbook listing all the shortcuts you’ll ever need. And because it’s in Excel, it’s sortable and filterable. Find one you like and try to put it to use today. Thanks Jacques for putting the list together.

Want to kick it up a notch? Set aside some time today where you only navigate windows folders with the keyboard. Here are some tips to get you started:

  • Turn on autocomplete in File Explorer. Press the Win key and start typing Internet Options. When the app shows up, arrow down to it and press enter. Use Ctrl+tab to get to the Advanced tab. Page Down and arrow down about 1/3 of the way and select Use inline AutoComplete in File Explorer and Run Dialog. Finally tab to the OK button and press Enter.
  • Win+E will open a new Windows Explorer window. Once there, Alt+D will put you in the address bar.
  • As you start typing, Windows will autocomplete folder names. If you type C:\u, Windows will likely autocomplete to C:\Users. Then you can press Tab to complete the entry or arrow down to a different entry if there is more than one. It would be nice if Windows would insert a \ for you, put you have to type that yourself.

Really want to show off? Create your own shortcut key in Excel using Appliction.OnKey. Put it in your PMW or in your general purpose utility addin. Mine is called UIHelpers.xlam. I use 27 different Appliction.OnKey lines in my Auto_Open procedure. Here are a few of my favorites:

See Incrementing Dates and Times for what those do. I don’t think I ever posted GetMappedAddress, so here it is.

It just puts the full path of the active workbook in the clipboard. I use it all the time to create a hyperlink in Outlook or to add it as an attachement. I just paste the full path in the File Name box and I don’t have to navigate to where the file is.

That’s a big long path pasted into File Name. Even though my current folder is My Documents, I just paste in that big path and hit enter and it’s done.

Finally, see Hyperlink Keyboard Shortcut Update and be sure to read the comments if you want to implement this one.

Have a great IKSD and leave a comment with how you’ll be celebrating.

Excel VBA Masterclass Ljubljana

Great news for anyone who would like to combine visiting the beautiful city of Ljubljana and learn about Excel VBA coding techniques!

On Novermber 5th, 2018 I’ll be teaching the Excel VBA Masterclass in Ljubljana.

In short I’ll be addressing:

  • Classes in VBA
    • Classes and Objects
    • Instantiating a class
    • Methods, properties, Events
    • Event classes
    • Instantiating an object from a class
    • Classes of classes
  • Userforms
    • Design
    • Events, methods, properties
    • Making a userform sizable
    • Splitter bars
    • Using in an Object oriented way
  • Efficient coding in VBA (2 sessions, one theoretic one and one hands-on lab)
    • Measuring performance
    • Break the rules
    • Fast VBA algorithms
    • Micro-optimization
    • Efficiently exchanging information with Excel

There are still some seats available, so hurry up and register soon!

Jan Karel Pieterse

PS: There are two other very interesting masterclasses on that same day, so if you are not into VBA (I can’t imagine you aren’t) there are alternatives!

Develop Excel Conference, London, October 18

On October 18 some of the world’s leading authorities on extending Excel using JavaScript, .NET, Python, VBA, and C++ will be flying in to London to present at our major community-driven not-for-profit conference on Excel Extensibility, “Develop Excel”.

If you are a developer or responsible for building Excel-based addins and solutions you really owe it to yourself to come and meet the speakers, hear the latest thinking on Excel extensibility and discuss the impact to your addins and solutions of the changes that Microsoft is making to core Excel function (including any changes announced at Microsoft Ignite September 24-28).

This is a unique conference: never before have so many Excel world-class developers gathered together to share their knowledge.

For details of the sessions see here

Conference places are filling up fast: make sure you register soon!


Copying and Filling Table Totals

Suppose you have a table with a number of columns.

And suppose you wanted to sum the Num6 column. You’d select a cell in that column and use Alt+JT+T to add the totals row.

But Excel always sums the last column (that it’s able to) when it should really sum the one you’re on. That’s an easy enough fix

That won’t stop the last column from also being summed, but it’s easier to destroy than create. I’ll let that happen and go delete it if I don’t want it. But we’re not done yet. The craziness is just starting. By the way, I’m using Office 2010. If they fixed any of this stuff in later versions, bully for them, but I’m still not upgrading.

The formula to sum Num6 is: =SUBTOTAL(109,[Num6]). If I copy and paste that to Num5

The formula stays the same. That’s consistent with how copying formulas that use Structured Table Referencing (STR), but it really stinks in this case. If I want to sum all of the columns, I have to go select the appropriate aggregate function from the list. I could change the STR into normal cell references, but then I lose the table goodness.

One option is to select a cell in Num5 and press Alt+JT+T+Alt+JT+T. Turning the totals row off and then on again sums up for that column by calling the code I wrote above. The fact that this works means I should have check to see if there was already an aggregate in the cell before I overwrote it. That is, if I had a count formula in there and turned the total row off and then on again, I’d kill that row. If I fix that, this workaround doesn’t work. But it’s the right thing to do.

Well that doesn’t work. If I have =SUBTOTAL(103,[Num5]) in the cell and turn on and off the total row, it changes to =SUBTOTAL(109,[Num5]).

I think what’s happening here is that Excel tables have a good memory. Once I change the aggregate to sum, that becomes the default for that column. When you show totals for the first time, the event sequence is (with the Target in parentheses)

  1. Add the total row (A5:H5)
  2. Add the total label (A5)
  3. Aggregate the last column (H5)

When I re-show the total row after having changed the aggregate, the event code changes the default aggregate, and when the table restores the formula it’s using the that aggregate. Assume I’m in Num7 when I show totals the first time. Then I move to Num5, add a count, and hide and show totals.

Event Target Num5 Default Aggregate
Show Totals 1st time A5:H5 SUM
Add label A5 SUM
Aggregate Num7 (automatic) H5 SUM
Add Count to Num5 (manual) F5 COUNT
Hide Totals A5:H5 COUNT
Show Totals 2nd time A5:H5 COUNT
Change Event F5 SUM
Add label A5 SUM
Aggregate Num5 (automatic) F5 SUM
Aggregate Num7 (automatic) H5 SUM

The second-to-last change is Excel restoring the Num5 total from the last time. It doesn’t restore it to what it was, it restores it to whatever the last aggregate used was. Since I interjected some code between the adding of the row and the restoration of the aggregate, I changed the default for that column. At least I think that’s what happening.

Hyperlink Formula Events

I like to use hyperlinks as user interface elements. They sit nicely in a cell, blend nicely with the surrounding data, and are well understood by users (blue underline means click here). Typically I’ll create a hyperlink that points to itself and then use the FollowHyperlink event to do stuff when it’s clicked.

If a user were to insert rows or columns the hyperlink moves but not the cell it refers to. That is, inserting a column to the left will move the hyperlink to E3, but it will still point to D3. I don’t like it, but it’s not a deal breaker. It means that I can’t use the location of the link to determine which hyperlink was clicked. This is bound to fail:

I tend to use the caption, which, unlike the example above, is generally meaningful and unique. But not always.

If each link points to a different place, I could use the SubAddress property

If there’s a space in the sheet name, there needs to be quotes around it. And if someone changes the sheet name, it mucks up the whole hyperlink. So there are a few things that can go wrong.

My biggest pet peeve is that I can’t use the HYPERLINK() function and the FollowHyperlink event together. That event only responds to inserted hyperlinks, not to links created by a formula. The use case for this is that I could add a column to a Table that had the HYPERLINK() function in it and that formula would automatically expand as the table expanded. Here’s a really contrived example.

When the user clicks a Jump link, it should go to that page. So in the case, the data I need is in the first column (the name of the sheet). Here’s a method I’ve been working on using the SheetChange event. When the user clicks on C2, that cell is selected. Then the link takes the user to A2 and that cell is selected. So I’m looking for a combination of column C then column A.

The module-level variable holds the last cell that was selected. If the currently selected cell is in the first column of the Table and the last cell was two cells to the right, it’s a match. If you’re wondering why I included the seemingly meaningless data in the second column, I’ll tell you. This method fails a lot if the two columns are adjacent because any time you arrow to the left through the table, you’d fire off the code. Having a column B in between fixes that.

You’ve probably already guess that there are a few problems with this. You could arrow to somewhere in the Jumper column and then click in the Number column and trigger the code when you didn’t expect to. Plus whenever you’re dealing with selections, you need to account for multi-cell selections, which I don’t here. But I’m going to try it out and see how it goes.

One side effect of this was that it broke my keyboard hyperlink clicker. It used to look like this.

When you use a ROW() function in the hyperlink address, the Evaluate returns a Variant array and this results in a Type Mismatch error. The relevant parts have been changed to

Now if the result is a Variant array, it pulls the first element.