FillSeries Keyboard Shortcut

I have never found a decent keyboard shortcut for filling a series, despite being the self-anointed king of all things keyboard. Oh sure, I could Alt+E, I, S, Enter, but it's just not satisfying. So in the vein of selecting adjacent columns, I added a macro to my Personal.xls.

Sub FillSeries()
   
    Dim lFirstBlank As Long
   
    If TypeName(Selection) = "Range" Then
        If Selection.Columns.Count = 1 Or Selection.Rows.Count = 1 Then
            lFirstBlank = GetFirstBlank(Selection)
            If lFirstBlank> 1 Then
                If Selection.Columns.Count = 1 Then
                    Selection.Cells(1).Resize(lFirstBlank - 1).AutoFill _
                        Selection, xlFillSeries
                ElseIf Selection.Rows.Count = 1 Then
                    Selection.Cells(1).Resize(, lFirstBlank - 1).AutoFill _
                        Selection, xlFillSeries
                End If
            End If
        End If
    End If
   
End Sub
 
Function GetFirstBlank(rRng As Range) As Long
   
    Dim i As Long
   
    i = 0
   
    For i = 1 To rRng.Cells.Count
        If IsEmpty(rRng.Cells(i)) Then
            GetFirstBlank = i
            Exit For
        End If
    Next i
   
End Function

It makes some assumptions that you don't have to make when you use the mouse. Everything above the first empty cell defines the series and the entire selection is the destination. Here are some examples where I select 10 rows:

Before:

After:

The first column is pretty straight forward. In the second column, the 12 is blown away because it's below the first empty cell. In the third column, the first cell is empty so nothing happens. In the last column, there are no empty cells, so nothing happens.

Finally, I updated my Auto_Open/Close procedures to assign a shortcut key.

Sub Auto_Open()
   
    Application.OnKey "^%{DOWN}", "SelectAdjacentCol"
    Application.OnKey "^%{RIGHT}", "FillSeries"
   
End Sub
 
Sub Auto_Close()
   
    Application.OnKey "^%{DOWN}"
    Application.OnKey "^%{RIGHT}"
   
End Sub

Determine Which COM Add-ins Are Installed

The COM Add-in (Component Object Model) toolbar button is not on any toolbars by default. You have to add it and then click on it to get to the COM Add-in dialog. First, right click in a blank area around the toolbars and choose Customize

Go to Tools on the left and COM Addins on the right

Drag it onto an existing toolbar - the I bar tells you where it's going to go

Now it's on the toolbar, so click it

And you get this dialog. It shows that I have one COM Add-in that it's not loaded (unchecked).

Andrew’s Excel Tips

Just a quick post to let everyone kind enough to visit - my site address has now changed to www.andrewsexceltips.net (formerly www.andrewsexceltips.com).

I've been blogging for over 4 years now, and although I don't post as often as I used to, I'm still cooking up new stuff to add.

Thanks to Dick and my other great Excel friends for their support and inspiration!

Peltier Loves Pie

I'm testing out widgenie (beta) and want to see how an embedded chart looks. I chose a pie chart because I've been reading lately how we all know pie charts are bad.

Anyway, this took about 10 seconds to create with Debra's sample data.

Lookup Second Occurrence

I need to do a VLOOKUP but find occurrences later than the first one. I've listed out all of my assemblies and all of their component parts like so:

Parent Child Quantity

To list the the children of a particular parent, I need a function that can find multiple occurrences of the parent. I considered a pivot table, but it's just too bulky to shoehorn into my existing template. I also considered an advanced filter, but I need to limit the list to the first 10 children.

I settled on a UDF. That way I could call it form a worksheet or from code if the need arises. I called it CLOOKUP for component lookup since I'm looking up raw materials components that make up a finished assembly.

Public Function CLOOKUP(vAssembly As Variant, _
    rLookup As Range, _
    lColumn As Long, _
    lOccurance As Long, _
    Optional vIfError As Variant) As Variant
   
    Dim sAssembly As String
    Dim rFound As Range
    Dim i As Long
    Dim sFirstAddress As String
    Dim rAfter As Range
    Dim vErrReturn As Variant
   
    If TypeName(vAssembly) = "Range" Then
        sAssembly = vAssembly.Value2
    Else
        sAssembly = vAssembly
    End If
   
    'find the first occurance
    Set rAfter = rLookup.Columns(1).Cells(rLookup.Columns(1).Cells.Count)
    Set rFound = rLookup.Columns(1).Find(sAssembly, _
        rAfter, _
        xlValues, _
        xlWhole)
   
    If Not rFound Is Nothing Then
        If lOccurance> 1 Then
            sFirstAddress = rFound.Address
            For i = 2 To lOccurance
                Set rFound = rLookup.Columns(1).Find(sAssembly, rFound, xlValues, xlWhole)
                If rFound.Address = sFirstAddress Then 'if not enough occurances, return NA
                    Set rFound = Nothing
                    Exit For
                End If
            Next i
         End If
    End If
   
    If IsMissing(vIfError) Then
        vErrReturn = CVErr(xlErrNA)
    Else
        vErrReturn = vIfError
    End If
   
    If rFound Is Nothing Then
        CLOOKUP = vErrReturn
    Else
        CLOOKUP = rFound.Offset(0, lColumn - 1).Value2
    End If
   
End Function

The first three arguments are the same as VLOOKUP. The fourth argument is the occurrence of vAssembly in the list. It will return NA if asked for an occurrence that doesn't exist. Finally I added an optional IfError argument. Errors default to NA like VLOOKUP, but I didn't want to have to wrap all these calls in =IF(ISNA(..)).

In the first section I test to see if vAssembly is a Range object and store its Value2 property if it is. Since the Value property is the default property of Range, this is really not necessary. I'm trying to get in the habit of using Value2, even though it's meaningless in the this context.

Next I use the Find method to find all of the occurrences of vAssembly. If I run out, I set rFound back to Nothing and that's my trigger for returning an error. I wasn't able to use FindNext in a UDF. Mike_R says:

Yeah, the list of commands that can modify the cursor and therefore are off limits to User Defined Function (UDFs) include: SpecialCells, CurrentRegion, CurrentArray, Find (xl 9.0 and below), Replace, GOTO, SELECT, PRECEDENTS, AutoFilters, AdvancedFilters, etc..

I'm surprised I've never run into that before. Or maybe I have and just forgot. So I just use Find again and I have to repeat the arguments. No big whoop.

Next I see if vIfError is specified and set the appropriate return error value. Finally, I test if rFound is Nothing and return the offset or the error value.

There's a little work to do on this function, such as if the column is beyond the lookup range. I'd also like to be able to pass in an array for the lookup range, but this works for now.

Office Community Clips

Have you seen the new Microsoft Office Community Clips?

People upload videos that demonstrate how to perform a task. I guess people like this because it's almost like watching TV. Never mind that you actually have to click and watch in order to determine if it's useful. And, a 3-minute video contains roughly the same content that you could read in about 20 seconds.

It's billed as a "community." Anybody can watch the videos, but to contribute one, you must be a member of the community. I think this means that you must have a Windows Live ID. Is that the same as a Passport? I have no idea. In the past few years, I've told Passport (or whatever it's called) to "remember me" at least 100 times. But I'm forgotten every time. But I've come to expect it, so it's no longer a big deal.

Joseph Chirilov, at the official Microsoft Excel blog seem to like Community Clips (but then again, could he really say that he hates it?):

The folks over in Office Labs are testing out a new idea called Community Clips and I, personally, think it's a fantastic idea. It's a community site where anyone, not just Microsoft employees, can upload "how to" videos that take you step-by-step through accomplishing a particular task. Think of it as YouTube meets Office Online. If, like me, you're a visual learner, this is a great way to learn new tips and tricks on how to do any number of things with Microsoft products. There are already quite a few Excel-related topics, from using freeze rows to creating your own UDFs in VBA.

I guess I'm not a visual learner. Watching these videos is almost painful to me. It's all so slow and inefficient, and I can't easily skim to get to the relevant part.

So what do you think? Are videos a viable way of learning?