Wednesday, 20 May 2015

AET Find and Replace v1.2

A while back, Jeff Weir, author of the upcoming Excel for Superheroes & Evil Geniuses and supreme guest blogger at the Daily Dose of Excel asked me about adding some functionality to my AET Find and Replace tool. (Jeff devotes part of his book to Find and Replace that I think you'll find interesting reading, a blurb on my tool is included!)

And here it is - the new improved version with lots of goodies!

Find and Select


Find and Replace
 photo AET Find And Replace v1.2 2 s_zpszxklvcgh.jpg

Let's take a closer look...

Adding Fields
As the name suggests, the simplest way is to click the Add Fields button, which adds a row of fields to the bottom of the form.

 photo AET Find And Replace v1.2 3 s_zpsuuxgfyya.jpg

You can also use the Enter Fields From Range button (copy values for Find, Replace and Exclusion fields directly from cells) or the little blue + buttons to insert a row of fields directly above the row that the button is next to.

Deleting Fields
Again, use the Delete Fields button to remove the row of fields at the bottom of the form.

You can also use Clear All Fields to remove all fields except the top one. It's fields will show as blank.

Or you can use the red X buttons to remove the row of fields that the button is next to.

Part or Whole Option Buttons
Use the Part and Whole option buttons at the top to set the default for all field rows. You can also set individual rows to Part or Whole if required.

Note that you can use * and ? as wildcards in searches.

* can be used for multiple characters such as E*l to find Excel (or Evil in Jeff's case)

? can be used for single characters such as W?rd to find Word (but who would want to?)

Exclusions
I can see you looking at that. Panting as you do so.

Okay, one of Jeff's coolest ideas was the ability to use Exclusions to be ignored in searches. (Along with entering values from ranges, deleting field rows directly and part/whole settings per field row).

He also said it would be good if users could use multiple exclusions per field row using commas.

Here's an example. Note there are 2 exclusions for the first row of fields.
 photo AET Find And Replace v1.2 4 s_zpsb5rg9u9o.jpg


And the end result.
 photo AET Find And Replace v1.2 5 s_zpsyet8u35j.jpg

Here's the download link. (Excel 2007 and above)

Wednesday, 22 April 2015

STDEVIF

Excel does not have a STDEVIF function. It's got other functions like COUNTIF(S), SUMIF(S) and AVERAGEIF(S), but is somewhat lacking when it comes to calculating conditional standard deviation.

If you have a lot of data, that can be a problem. Using array formulas or a UDF can slow things down. So let's focus on what's important, why not just get the calculation results? Forget using functions or VBA, why not both? (This applies to hard and soft tacos also!)

Here's my data. Note that the values in Column A are sorted. This is important.

 photo STDEVIF 1_zpscd11x9x8.jpg

In my little code snippet down below,

I want to add headers so I know which column to refer to, so bAddHeaders = True.

The headers are in Row 1, so lHeaderRow = 1.

Conditions (Class numbers in this case) are in Column A, so iCondCol = 1.

The values start in Column B, so iValsStartCol = 2.

The number of columns to calculate are 3 (Columns B:D), so iNumbOfCols = 3.

I'll put the results in Column F, so iEnterValsStartCol = 6

And I'll choose StDev for sFunctionType. I've also added Max for MAXIF and Min for MINIF, but feel free to add your own.

Update: Since I wrote this post, Microsoft launched Excel 2016 which includes MAXIF(S) and MINIF(S) functions. But like I say, this method is still very useful for a lot of other functions that don't have conditional variations yet! So for STDEVP, STDEV.S, STDEV.P, etc, substitute where necessary.

Here we go...

Sub GetConditionalData()
    Dim sFunctionType As String
    Dim lHeaderRow As Long
    Dim bAddHeaders As Boolean
    Dim lStartRow As Long
    Dim iCondCol As Integer
    Dim iValsStartCol As Integer
    Dim iNumbOfCols As Integer
    Dim iEnterValsStartCol As Integer
    Dim iCol As Integer
    Dim rCell As Range
    Dim rCond As Range
    Dim rAddVal As Range
    Dim rColumn As Range
    Dim sTemp As String
    Dim lCalc As Long
    
    On Error Resume Next
    
    'Change function type, columns, and headers as necessary
    '********************************************************
    
    'This code currently allows StDev, Max and Min
    'Add your own function types as required (See code below)
    sFunctionType = "StDev"
        
    'Add column headers
    bAddHeaders = True
    
    'Which row has the headers?
    lHeaderRow = 1
    
    'Which row does the data start?
    lStartRow = 2
    
    'Which column has the conditional data?
    iCondCol = 1
    
    'Which column do the values start?
    iValsStartCol = 2
    
    'How many columns to loop through?
    iNumbOfCols = 3
    
    'Which column to enter the calculated values?
    iEnterValsStartCol = 6
    
    '********************************************************
    
    Select Case sFunctionType
        
        'Add function types here
        Case "StDev", "Max", "Min"
        
        Case Else
        
        MsgBox "You did not choose an included function.", vbExclamation, "Get Conditional Data"
        
        Exit Sub
        
    End Select
    
    With Application
        lCalc = .Calculation
        .Calculation = xlCalculationManual
        .ScreenUpdating = False
        .EnableEvents = False
    End With
    
    With ActiveSheet
        
        For Each rCell In Range(.Cells(lStartRow, iCondCol), .Cells(.Rows.Count, iCondCol).End(xlUp)).Cells
            
            With rCell
                
                If rCond Is Nothing Then Set rCond = rCell
                
                If .Value = .Offset(1).Value Then
                    
                    Set rCond = Union(rCond, rCell.Offset(1))
                    
                Else
                    
                    Set rCond = Nothing
                    
                End If
                
            End With
            
            If Not rCond Is Nothing Then
                
                For Each rAddVal In rCond.Cells
                    
                    For iCol = 1 To iNumbOfCols
                        
                        With Cells(rAddVal.Row, iEnterValsStartCol + iCol - 1)
                            
                            'You must add code for your function type here
                            Select Case sFunctionType
                                
                                Case "StDev"
                                .Value = WorksheetFunction.StDev(Range(rCond.Offset(, iValsStartCol - iCondCol + iCol - 1).AddressLocal))
                                
                                Case "Max"
                                .Value = WorksheetFunction.Max(Range(rCond.Offset(, iValsStartCol - iCondCol + iCol - 1).AddressLocal))
                                
                                Case "Min"
                                .Value = WorksheetFunction.Min(Range(rCond.Offset(, iValsStartCol - iCondCol + iCol - 1).AddressLocal))
                                                                
                            End Select
                            
                        End With
                        
                    Next iCol
                    
                Next rAddVal
                
            Else
                
                For iCol = 1 To iNumbOfCols
                    
                    With Cells(rCell.Row, iEnterValsStartCol + iCol - 1)
                        
                        'You must add code for your function type here
                        Select Case sFunctionType
                            
                            Case "StDev"
                            .Value = WorksheetFunction.StDev(Range(rCell.Offset(, iValsStartCol - iCondCol + iCol - 1).AddressLocal))
                            
                            Case "Max"
                            .Value = WorksheetFunction.Max(Range(rCell.Offset(, iValsStartCol - iCondCol + iCol - 1).AddressLocal))
                            
                            Case "Min"
                            .Value = WorksheetFunction.Min(Range(rCell.Offset(, iValsStartCol - iCondCol + iCol - 1).AddressLocal))
                            
                        End Select
                        
                    End With
                    
                Next iCol
                
            End If
            
        Next rCell
        
        'Get the Column headers if required
        If bAddHeaders = True Then
            
            For iCol = 1 To iNumbOfCols
                
                Cells(lHeaderRow, iEnterValsStartCol + iCol - 1).Value = Cells(lHeaderRow, iValsStartCol - iCondCol + iCol).Value
                
            Next iCol
            
        End If
        
        With Range(.Cells(lStartRow, iEnterValsStartCol), .Cells(.Rows.Count, iEnterValsStartCol).End(xlUp)).Resize(, iNumbOfCols)
            
            'Enter zeroes in blank cells (eg, calculating StDev was not possible)
            .SpecialCells(xlCellTypeBlanks).Value = 0
            
            'Delete duplicates (comment out this code if you want to keep them)
            '******************************************************************
            For Each rColumn In .Columns
                
                For Each rCell In rColumn.Cells
                    
                    With rCell
                        
                        sTemp = Cells(.Row, iCondCol).Value
                        
                        If Cells(.Row, iCondCol).Offset(1).Value = sTemp Then .Offset(1).Value = ""
                        
                    End With
                    
                Next rCell
                
            Next rColumn
            '******************************************************************
            
        End With
        
    End With
    
    With Application
        .Calculation = lCalc
        .ScreenUpdating = True
        .EnableEvents = True
    End With
    
    On Error GoTo 0
End Sub

And we're done.

 photo STDEVIF 2_zpsc3rrhsoe.jpg

The code used the VBA version of STDEV (WorksheetFunction.StDev) to calculate the results, and put them in the appropriate column. So yeah, functions and VBA, Excel has fun for everyone.

Note the code deletes duplicates. I figure just one result per condition from each of the value columns is enough.

If you're using the data to print reports, like results per class, just use a LOOKUP function variant or MATCH/INDEX combination to find the relevant values.

How about STDEVIFS? Sure, just use suitable functions to get a unique string in a helper column, and refer to it instead. Then make sure it's sorted and you're good to go.

See you next time.



Friday, 17 April 2015

AET Data Checker v1.1

A while back I promised a new version of my AET Data Checker addin... and I just uploaded it!

What's new?

1. Dropdown lists to select columns. This enables you to use your keyboard arrow keys to scroll across columns without having to type them in like before. The benefit is that you can just "scroll" across columns and watch the values change.

2. You can show percentages, including to the number of decimal places you like.


(This is the first video of my YouTube channel. Please subscribe to watch more!)

Don't forget,

= means spaces

<> means non-spaces (numbers and text)

<>= means everything

Here's the download link.

Coming soon

An even better version of my much-loved AET Find and Replace tool (Thanks Jeff for your suggestions!)

An interesting non-array / non-UDF way to get conditional data. (STDEVIF? No problem!)

And more tools added to AET Excel Utilities (but don't wait for the new version because updates are free!)

See you next time.

Saturday, 4 April 2015

The Amsterdam Excel Summit

Just a quick heads up - The Amsterdam Excel Summit is coming up on the 13th and 14th of this month, and there's a last minute discount available of € 200 per attendee for both days or € 100 for one day!



Looking at the list of top level speakers (as in literally some of the world's best), I can vouch that if you can go, it will be well worth it.

Day 1

Day 2

Here is a link to the registration page.

Do yourself a favour and sign up now!


Friday, 3 April 2015

AET Excel Utilities, Uploaded (Finally!)

Dick Kusleika from the Daily Dose of Excel site has very kindly allowed me to post about my AET Excel Utilities on his blog.

That's right, they're finally uploaded, just waiting for you to try them out (for a small price!).



Read all about them here.

Or go straight to the download page here.

To be honest, it's a big relief to finally get them ready. I've neglected this blog of late and have some other interesting stuff I want to post about :-)

See you next time.