(post inspired by Eugenia Chen’s wsj article)

“A sequence in which the numbers increase by the same amount at each step” (source).

Try to calculate this in your head:

Start with 2. Add 4 to it 10 times.

What’s the SUM? What’s the MEDIAN?

These are the values: 2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42. SUM is 242 and MEDIAN is 22.

Long sequences were very difficult even for mathematicians before calculators and computers.

It’s easy to create sequences in Excel. (Excel file: save to computer and then open).

These are the inputs.

Below is a non dynamic array solution that is backwards compatible.

And finally the calculations:

My solution above contains several steps. Let’s create sequence values from a single formula!

**Option A**

=SEQUENCE(C2,,A2,B2)

=TEXTJOIN(“, “,TRUE,SEQUENCE(C2,,A2,B2))

SEQUENCE is a dynamic array. Requires Office 365 Excel version. TEXTJOIN keeps it from spilling.

**Option B**

=TEXTJOIN(“, “,TRUE,B2*ROW(INDIRECT(“1:”&C2))-A2)

Formula above is an array and requires Control Shift Enter (just not Enter).

**Option C**

=B2*ROW(INDIRECT(“1:”&C2))-A2

Formula above doesn’t require Control Shift Enter (just Enter). It spills down into the cells below.

(download my pbix file.)

GENERATESERIES quickly creates a sequence:

Sequencev1 = GENERATESERIES(2,42,4)

Start with a 2, end at 42, intervals of 4. GENERATESERIES creates a table with 1 column.

Below I use variables but it does the same thing as above. So, is it really necessary?

Sequencev2 =

var SeqCount = 11

var SeqInterval = 4

var SeqStart = 2

var Final = GENERATESERIES(SeqStart,SeqCount*SeqInterval-SeqStart,SeqInterval)

return

Final

Both DAX versions above contain only internal inputs. Could I connect to an input from outside?

After experimenting I created a measure that I referenced when creating a new table.

Here’s the measure:

DistinctProductKeys = DISTINCTCOUNT(FactTable[Product Key])

Here’s the new table that references the measure above:

DynamicSequenceTBL = GENERATESERIES(1,[DistinctProductKeys],1)

If the distinct count changes this viz also updates. GENERATESERIES table function wants 3 single values (start, end, increment). It’s ok for a measure to be the end value. We could use measures for start and increment values as well.

My dad was really good at math. We would quiz him with multiplication and division questions. He seemed to be able to calculate anything. Hmm…maybe he would also fake some answers knowing that we wouldn’t know the difference.

I don’t think even he could have calculated a simple sum for a long sequence in his head. I bet he would’ve been a big spreadsheet and database fan. I remember that in the mid 1970s my older cousin had a calculator and it was a big deal. Around 1980 I went with my dad to visit his lawyer. He had one of those classic server room computers. I found it fascinating but it probably was less powerful than a smartphone from today.

**What’s next?** Imagine what things will be like forty years from now. Today’s technology will be ancient.

My name is Kevin Lehrbass. I live in Markham (near Toronto) Ontario Canada.

I’ve been working with data for almost 20 years now. SQL (various databases), Excel and now Power BI (DAX).

I find it all so interesting that I also have this blog

]]>(Post concept from Tom Urtis. Visit Tom’s blog)

In rare cases this could be extremely helpful. Instead of using vba to store all values and then use MIN and MAX functions you could use Tom’s vba solution.

(download my Excel file)

I modified Tom’s code a bit to also include an all time maximum (along with all time minimum).

Private Sub Worksheet_Change(ByVal Target As Range)

With Target

If .Address <> “$A$2” Then Exit Sub

If Len(.Value) = 0 Then

Exit Sub

End If

If .Value < Range(“B2”).Value Then Range(“B2”).Value = .Value

If .Value > Range(“C2”).Value Then Range(“C2”).Value = .Value

End With

End Sub

With Target

If .Address <> “$A$2” Then Exit Sub

If Len(.Value) = 0 Then

Exit Sub

End If

If .Value < Range(“B2”).Value Then Range(“B2”).Value = .Value

If .Value > Range(“C2”).Value Then Range(“C2”).Value = .Value

End With

End Sub

Worksheet_Change is a special kind of vba. It monitors a cell or range and performs an action when a condition(s) is met.

The code above performs various checks. If the activecell isn’t cell A2 then stop (exit sub). If the length of cell A2 is zero then stop. If the code is still going it means that the current cell is A2 and the length of cell A2 is not zero.

If .Value < Range(“B2”).Value Then Range(“B2”).Value = .Value

If cell A2 value is less than cell B2 value then take A2 value and put it in cell B2. This keeps the all time minimum value. The all time max works the same.

Years back I was having a discussion with a work colleague. He said “Oh, Excel can’t do that!”. My response was “Oh yes it can”. This is what I built to prove him wrong

In the light brown input area enter words (or numbers). Those words will be stored in column F. If you type over a word the original word is still stored in column F (in the same order) and the new word is added further down.

Here’s the code:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim nextrow As Integer, Savetxt As Range

Set Savetext = Range(“A1:D5”)

nextrow = Application.WorksheetFunction.CountA(Savetext)

With Target

If Target.Column > 4 Then Exit Sub

If Target.Row > 4 Then Exit Sub

Dim nextrow As Integer, Savetxt As Range

Set Savetext = Range(“A1:D5”)

nextrow = Application.WorksheetFunction.CountA(Savetext)

With Target

If Target.Column > 4 Then Exit Sub

If Target.Row > 4 Then Exit Sub

On Error GoTo Handler

If Len(.Value) = 0 Then

Exit Sub

End If

Exit Sub

End If

Range(“F” & nextrow + 1).Value = .Value

End With

Handler:

Handler:

End Sub

I got a bit lazy with the code and used On Error GoTo Handler to hide my incompetence (you’ll see).

Well…thanks again to Tom Urtis. Unfortunately I couldn’t find my original code for the multi cell input area but I was able to recreate it to do pretty much the same thing. I think now I’ll get some more coffee and study Power BI and DAX.

He’s an Excel consultant, Excel MVP, and Excel legend!

Tom is also a big sports fan (baseball and football).

Visit his blog: https://www.atlaspm.com/

My name is Kevin Lehrbass. I’m a Data Analyst from Markham Ontario Canada.

In these difficult times of Covid-19 I’m keeping my mind occupied here at home by playing around in Excel and Power BI. Wait…I always do that! I’ve also calculated the optimal balance of news and comedy. Oh yeah…these are my dogs Fenton and Cali. Starting yesterday the neighbourhood kids aren’t running around outside so they have nothing to bark at.

]]>

Washing hands, staying home, etc slows down the spread which flattens the curve, relieves pressure on hospitals and saves lives. Let’s all do our part.

We’ve seen the chart on the news. Here’s one from CBC news:

The health care system is limited (dotted constant line). We need to reduce the height of the red curve so it fits within health care system capacity.

Download my Excel file (save to computer and then open it).

My formulas create **fake demo data** for 2 bell curves. The red one quickly spikes upward and past the health care dotted line while the green one (based on our positive actions) doesn’t peak as high and spreads out more to the right.

**NORM.INV function**

NORM.INV function creates the bell curves. It has 3 arguments:

‘mean’ and ‘standard_dev’ define the curve’s dimensions. ‘mean’ is the average of all the numbers and ‘standard_dev’ defines the spread of the data-set. A big number = a big spread (flatter), a small number = a peak around the mean.

‘probability’ creates a value within this dataset.

**NORM.INV Formula**

=NORM.INV(RAND(),$B$2,$B$3) depends on variables in cells B2 and B3. RAND function creates a random value within our data-set. If we drag this formula down far enough we’ll have a smooth curve clustered around the mean.

**Binning the Numbers**

I created groups (aka binning) to make it easier to read the data.

Finally I created the chart that we saw above. Don’t forget that the data changes due to the volatile RAND function…and feel free to play around with the ‘mean’ and ‘standard_dev’ variables.

Download my pbix file.

To make it interesting I decided to **create everything in Power BI. No external data allowed!**

I researched the DAX to create bell curve numbers. But it’s not possible to create a measure until we have a table!

**How can we create a table without importing data?** I used table function GENERATESERIES.

On the ribbon click ‘Modeling’ and ‘New Table’ then enter this DAX and press enter:

Table1 = GENERATESERIES(1,2000,1)

Click the ‘Data’ icon on the left side of the screen to see our new table! It has one field called ‘Value’ with 2000 rows.

**Add DAX helper columns to create bell curve data.**

As there’s only 1 table new columns are automatically added to Table1. Click ‘New Column’ and add DAX below:

BellCurve1 = ROUNDDOWN(Norm.inv(rand(),300,60),0)

BellCurve2 = ROUNDDOWN(Norm.inv(rand(),300,100),0)

Now Table1 has 3 columns: Value, BellCurve1, BellCurve2.

**Making the Chart**

Hover over field BellCurve1. On right side click the 3 dots and select ‘New Group’. Change bin size to 50, press ‘Ok’.

Drag new column ‘BellCurve1 (bins)’ into the canvas. It should default to a Clustered Column Chart.

Add ‘BellCurve1’ to the Value area. With the chart selected, select ‘Line Chart’. Add ‘BellCurve2’ to the Value area.

Add constant line: Under Visualizations click magnifying glass (Analytics), ‘Constant line’, ‘Add’, with value of 200000.

Here’s the Power BI demo chart. Remember that it’s based on RND (random) so it changes.

**Make Table Alternative #1**

GENERATESERIES is amazing but it’s not the only way. I created the same table (1 counter column) in Power Query!

- Open Power Query: On the ribbon select ‘Home’ and ‘Transform data’ (could be ‘edit queries’ in your version)
- Home / New Source / Blank Query
- In formula bar paste this code: =List.Numbers(1,2000,1)
- Top left click ‘To Table’ and press ‘ok’
- M code looks like this: = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error)
- Top left click ‘Close & Apply’

Our ‘Query1’, created inside Power Query, is now a table here in Power BI’s data model. Cool!

**Make Table Alternative #2**

This DAX method is longer than GENERATESERIES but it’s interesting and worth reviewing.

Table2 =

VAR MINcounter = 1

VAR MAXcounter = 2000

RETURN

SELECTCOLUMNS(

CALENDAR( MINcounter, MAXcounter ),

“xNumber”,

INT ( [Date] )

)

I could use CALENDAR function to create a new table. On ribbon: Home / New Table:

zTable = CALENDAR(1,2000)

Yes, it creates a new table but it has 2000 dates and we want numbers 1 to 2000. I tried to wrap CALENDAR function with INT function but that didn’t work (probably because CALENDAR is a table function not a column).

So, wrap CALENDAR function with SELECTCOLUMNS to convert dates to integers. SELECTCOLUMNS has 3 parts:

- a table: CALENDAR( MINcounter, MAXcounter )
- a column name: “xNumber”
- an expression: INT([Date])

The DAX code in Table2 creates a table with 1 column named ‘Date’ and 2000 rows.

Note: I used variables (VAR) to store min and max numbers later used inside CALENDAR function. Not a big difference but in longer DAX statements using variables makes it so much easier to read.

Creating the excel file, pbix file and writing this post really helped me focus on something else besides you know what. I don’t know everything about Excel but I’ve used it for many years. The real challenge was researching the M and DAX code and implementing it in Power BI. I have a fair amount of theoretical knowledge but hands on building is essential.

More positive distractions include watching:

- Big Bang Theory
- Two and a Half Men
- Seinfeld
- Men in Black 3

We need to be informed but we can’t worry constantly. **What are you doing to have fun or distract yourself?**

My name is Kevin Lehrbass. I’m a Data Analyst and live in Markham Ontario.

Hopefully we’ll look back at the Covid-19 crises saying things like “I’m glad we took those steps to slow it down”. Time will tell.

Here’s a post about standard deviation based on height. It proves that I’m not always a freak. It depends on my location.

]]>Excel file (original file from Bill Jelen) used in this post (read his original post).

Someone attending one of Bill’s training sessions had this data-set:

…and needed to rearrange it into this:

Yes, it’s an amazing way to solve this but it requires a refresh if your data changes. Great thing about PQ is that it does all the work and drops the finished dataset back into a sheet (no formulas that need calculating). Nevertheless, I went old school with a formula helper column solution

Years back I’d often build a single monster array formula to solve something like this. Nowadays I prefer to break down a solution into a series of helper formulas that are easier to audit and explain to others.

**Getting Started**

My Excel file (original file from Bill Jelen) also contains an explanation.

Key question for re-arranging data: **What’s the pattern?**

Each data block at the top (moving right) is to be stacked below. Total columns above, below each employee name and to the left of each block, need to be to the right of each block below.

Before we create formulas to get these blocks let’s create formulas to display Category & Employee.

**Category & Employee**

For each data block we need to repeat ‘Category Description’ and ‘Employee Name’ multiple times.

Each one has 2 formulas: 1) helper that defines the position, 2) index function gets the answer.

This is the Category helper column:

There are 6 categories (cells C4 to C9).

Column A helper formula is a simple way to repeat sets of 1 to 6.

Simple Index function in column C uses this helper to get the category.

This is the Employee helper column:

Column D has this formula:

=INDEX($I$3:$AB$3,$B19)

It slides right along row 3 to get the Employee’s name.

Now it’s time to get the data!

**Get the Data**

Let’s look at cell F23. Formula is =INDEX($I$4:$AB$9,$A23,$B23+F$11)

We reuse helper values from columns A & B and the values in row 11.

Index range $I$4:$AB$9 has all answers.

$A23 = 5 (5th item down = “Project B”). $B23+F$11 = 8 (8th item across = “Q2”).

The intersection of 5th item down & 8th item across = 15 (yellow below).

Normally we wouldn’t have the desired result (sheet ‘original’). So, my formula in cell M12 of sheet ‘FINAL’ wouldn’t work.

A simple way to check results is to change a value at the top (original layout) and ensure that it changes below (desired layout). This is especially helpful if the data has low cardinality (many repeat values). Obviously you would change the value back to it’s original value after verifying it.

Splitting the solution into various helper formulas makes it easier to explain, audit and adjust. In rare cases I still use megaformulas (formula with numerous functions) but my advice is to be kind to others and also your future self by creating solutions that won’t cause pain and suffering. My solution is also backwards compatible.

Here is Bill’s original video that introduces the challenge. His summary post has links to the different groups of solutions (i.e. formula solutions).

Bill Jelen (Mr Excel) declares Bill Szysz’s Power Query solution the winner!

Don’t forget to visit Mr Excel’s Message Board where a team of volunteers answer your Excel questions for free!

That’s me Kevin Lehrbass on the left and Bill Jelen (Mr Excel) on the right.

I’m a Data Analyst. I live in Markham Ontario Canada (near Toronto).

This is my personal blog about Microsoft Excel. Here’s a previous post of mine that’s also about re-arranging data.

]]>

Robert realized **KFC** Kentucky Fried Chicken = **KFC** Kevin’s Formula Challenge

He then described the challenge:

**Using formulas, create KFC out of Kentucky Fried Chicken.**

It’s an acronym creator. Shortest formula wins!

I might have to add more rules later to clarify but let’s start with:

- extract only upper case letters
- each word starts with upper case letter
- each word has only one upper case letter
- text may or may not have spaces
- no accents on upper case letters
- sheet name is “x” (only 1 character)
- length must = count of upper case letters
- shortest formula wins

I later realized that there are 2 variations of this challenge:

- text contains only letters (upper & lower) and spaces
- text contains any kind of characters

If the text could contain any kind of character then the solution needs to be more robust.

Download my Excel file.. Post your formula as a comment below.

I came up with 3 solutions. Can you create a shorter solution?

Here’s my 1st formula. It’s 182 characters long:

=SUBSTITUTE(CONCAT(CHAR(IF((CODE(MID(A2,ROW(INDIRECT(“1:”&LEN(A2))),1))>64)

*(CODE(MID(A2,ROW(INDIRECT(“1:”&LEN(A2))),1))<91),

CODE(MID(A2,ROW(INDIRECT(“1:”&LEN(A2))),1)),

91))),”[“,””)

My 2nd formula is 140 characters long:

=SUBSTITUTE(CONCAT(IFERROR(CHAR(IF(CODE(MID(A2,ROW(INDIRECT(“1:”&LEN(A2))),1))

<91,CODE(MID(A2,ROW(INDIRECT(“1:”&LEN(A2))),1)))),””)),” “,””)

Normally, array formulas require Control Shift Enter. The { } array brackets. However, I have the new version with dynamic arrays. My formula works without Control Shift Enter. I save two characters!

**Cheating?**

My 3rd solution is the shortest but is it cheating?

Notice that in the formulas above I had to use this part twice:

=CODE(MID(x!A2,ROW(INDIRECT(“1:”&LEN(x!A2))),1))

So…I put this part in a named range called z. Now my formula is reduced to:

=SUBSTITUTE(CONCAT(IFERROR(CHAR(IF(z<91,z)),””)),” “,””)

The length of the named range and formula combined is 104 characters.

My 4th solution is more robust. It’s length is 114 characters.

=SUBSTITUTE(CONCAT(IFERROR(CHAR(IF(AND(z<91,z>64),z)),””)),” “,””)

Most formula solutions follow the same basic logic:

- extract each individual character
- CODE function converts characters to numbers
- keep numbers >=65 and <=90 (ignore everything else)
- convert numbers back to letters
- squeeze upper case letters together

**1. Extracting Characters**

To extract individual characters from a cell I know of 2 methods:

- MID(A5,ROW(INDIRECT(“1:”&LEN(A5))),1)
- MID(A5,ROW(A$1:INDEX(A:A,LEN(A5))),1)

Both have a length of 37 characters. The INDEX method is not volatile so it wins.

**2. Code Number**

CODE function converts each character to a number. Upper case numbers have codes from 65 to 90.

**3. Ignore All Else**

Functions IF or IFERROR ignore codes we don’t want.

**4. Numbers Back to Letters**

CHAR function converts numbers (65 to 90) back to letters. Dave’s (ExcelJet) solution didn’t use CHAR.

**5. Squeeze Together**

Functions CONCAT or TEXTJOIN squeeze remaining upper case letters together.

Feel free to share your VBA and Power Query solutions. We can count the text in a vba statement and I guess we could also count the M code text as well.

Before starting this post I had searched to see if this challenge had already been done on another Excel blog. I didn’t find anything but it just seemed like such a common challenge.

After writing this post I went back and changed search words a few times and eventually found that Dave at ExcelJet and Jeff Weir at Chandoo.org had created the same challenge. I then compared their solutions with mine.

I’m curious if there’s a shorter way to solve this for either variation: 1) cell contains only letters/spaces, or 2) cell contains any kind of characters.

So far it looks like this formula from Bill Szysz wins!

=CONCAT(FILTER(MID(A5,SEQUENCE(LEN(A5)),1),

ISNUMBER(MATCH(CODE(MID(A5,SEQUENCE(LEN(A5)),1)),

SEQUENCE(24,,65),0))))

It’s the shortest and seems to work with any kind of text. However, you would need an Excel version that supports dynamic arrays.

A special thanks to Robert Gascon for suggesting this challenge! Someday I’ll buy you some KFC!

My name is Kevin Lehrbass. I live in Markham Ontario Canada.

When I was a child (4?) my parents would sometimes speak in code. Once my older brother whispered that we were going to eat supper at Kentucky Fried Chicken! How did he know that? He had broken the KFC code!

I’m a Data Analyst and still a kid at heart.

]]>

Thanks to data.world and hockey.reference.com for this data-set.

It lists all 894 regular season NHL goals Gretzky scored.

There are 16 columns. Columns I & J are for assists.

Power Query (Get & Transform) made it easy to answer this question:

How many different players assisted on Gretzky’s regular season goals?

Stack the assist columns, remove duplicates and count the players. Answer? Take a guess!

Here’s an interesting question:

Did Gretzky ever score a short-handed empty net goal?

Here’s what I consider to be my **“great” question**:

Did Gretzky ever score a goal on a goalie who also assisted on one of his goals?

To clarify, not in the same game. Assisted on a goal when they were on the same team and Gretzky scored on the same goalie(s) before or after they were teammates.

I have 10 total questions. Can you think or an interesting question?

Download it here. I used Pivot Tables and Power Query (also an alternative formula/pivot solution).

**Pivot Tables**

If a data-set is already perfectly arranged, consolidated and clean then just use Pivot Tables! If not, it’s often possible to add a few formula helper columns. However, the data-set might need major alterations and Power Query is the tool!

**Power Query**

It’s easy to clean-up, re-arrange and summarize data with Power Query. Yes it can get complicated at times but there’s so much that can be done with a few simple clicks of the mouse.

To see the queries select: sheet ‘Power Query’, cell A3, above ribbon ‘Query Tools’ & ‘Edit’.

When I was 8 years old I heard that 6 WHA teams were going to join the NHL for the 1979-1980 season. I was shocked and excited! I didn’t even know that the WHA had existed. I endlessly pestered my dad with questions about the WHA. Gordie Howe, Bobby Hull and several others had been playing in the WHA and would rejoin the NHL!

However, it was the 18 year old kid from the WHA that took the NHL by storm and changed the game forever! It was magical. I don’t remember seeing Bobby Orr play. Gordie Howe (in his prime) and Maurice Richard were well before my time. When I think of the NHL it was Wayne Gretzky. He was not big or tough, he wasn’t the fastest but he was a magician with the puck. Skill and 1000s of hours of practice.

Alexander Ovechkin currently has 692 regular season goals as of today January 25, 2019. He is 34.

He’s on pace for about 48 goals this year. If he does score 48 goals and plays another 5 seasons scoring on average 38 goals then he can do it! It might all depend on his health.

Download my Excel file. Grey colored cells are inputs that you can adjust. In the 2nd sheet uncheck the boxes to exclude seasons.

My name is Kevin Lehrbass. I’m a Data Analyst.

I live in Markham Ontario Canada (near Toronto).

I would say that my love of numbers started with hockey and baseball cards in the late 70s.

]]>(read Alan’s LinkedIn post)

Alan received the data in this layout:

Each customer is allowed 1 appetizer, 1 main dish, and 1 dessert.

Columns A, B, and C are appetizers. D, E, and F are main dishes. G, H, and I are dessert.

Alan’s client wants to see the following outputs:

Order Count Per Food Item

Items Ordered Per Customer

Alan and Oz solved this using Power Query. Slightly different approaches but the same output.

Power Query is the best way to solve this. Given an awkward dataset, Power Query rearranges the data and solves both requirements. Final answers get pushed back into an Excel sheet.

(download my Excel file)

Some people insist on a formula solution. I was curious if Dynamic Arrays would make a formula solution easier!

(remember: dynamic arrays are a new feature. As of Jan 2020 most Excel users don’t have them)

**Requirement 1: Order Count By Food Item**

(a) COUNTA in row 1 counts food items.

(b) TRANSPOSE function rearranges data as required. Cell K3 formula spills across and down.

Just 2 quick steps solves this.

Transpose function is not new but it now spills!

**Requirement 2: Items Ordered Per Customer**

This part has several steps. We need to stack names, spread across columns A to I, into 1 column.

Column N is a growing range based on column K.

Column O is a simple counter. Columns P & Q give us the co-ordinates to extract the names.

Column R stacks all the names (including repeats).

Column S formula below spills unique name list. Add/change names in input area (columns A to I) and column S updates.

Formulas in columns T, U, and V extract selected food items for each customer.

Dynamic arrays make it easier to solve but it still requires multiple steps. Is there an easier solution?

(download my Excel file)

We often can’t change the data layout. **But what if we could? How would we change it?**

If Alan convinces the client to input the data in this format then the output takes seconds!

This is a pivot data layout. We have 3 things (Customer, Category, Food Item) so we need 3 columns.

We can make the first pivot in a few seconds.

Pivot Table 2 has a different look. It allows for multiple item orders and can also be created in seconds.

Power Query and formulas are so powerful but sometimes they aren’t necessary.

Teaching someone to setup their data in a database/pivot layout along with basic pivot table knowledge empowers them. It can lower their developer costs and turnaround time. It’s not enough to have clean data. It’s also important to have an optimal data layout.

If you can’t change the data layout then Power Query or a bunch of formulas save the day!

What if someone forgets to make a selection? What if someone orders too many items?

I made a copy of the data and removed a few rows to demonstrate how a Pivot can identify those who have less than 3 entries. True, someone could have ordered 3 items (2 desserts and 1 main). That would require a bit more work. But, the idea is that when the data is arranged properly it’s much easier to analyze it.

Alan Murray is from Suffolk England. He is an Excel and IT trainer.

Visit his blog and YouTube channel for hundreds of free tutorials! His videos are always clearly explained.

Alan also has Excel video courses that you can take.

Oz du Soleil (on the right, me on the left) lives in Portland Oregon.

He was an early Power Query adapter and has bounced around the globe training people in Excel. Oz has an extremely engaging and witty presentation style

He also has some amazing video editing skills!

This past week Oz presented at an Excel Meetup organized by Alan in London England.

My name is Kevin Lehrbass. I’m a Data Analyst.

I watched Alan’s video and then Oz’s video on an empty stomach. All the references to food made me really hungry! I had to stop and have some butter chicken and then some guacamole!

]]>(download my Excel file)

This is Bob Umlas. He is an Excel god.

Let’s examine his vba code.

It assigns checkbox status (checked or not) to column D and names each checkbox based on text from column F:

Sub Assigner()

For I = 1 to 10

Activesheet.Checkboxes(i).LinkedCell = Cells(i, 4).Address

Activesheet.Checkboxes(i).Characters.Text = Cells(i, 6).Value

Next

End Sub

This was the starting point for various procedures I ended up creating. Thanks Bob!

I created a simple non vba task list and then a more functional task list inspired by Bob’s vba.

**The Easy Way**

To cross off a finished item it’s easier to use a drop down list and conditional formatting. Quick to create but functionality is limited.

Tasks from movie ‘The Big Lebowski’

**The Complex Way**

Why use vba? If you have a long list of items vba can automate tedious tasks such as:

- check all checkboxes
- uncheck all checkboxes
- rename checkboxes
- create new checkboxes
- align checkboxes
- delete checkboxes

**Adding New Checkboxes**

‘Add Checkboxes’ (top of column K) was fun (and frustrating) to create.

Sub AddCheckboxesStartingInCurrentCell()

Dim actrow As Integer, SettingAddCheckBoxes As Integer, CBcount As Integer

CBcount = ActiveSheet.CheckBoxes.Count

Range(“A” & CBcount + 2).ActivateSettingAddCheckBoxes = Range(“SettingAddCheckBoxes”).ValueFor i = 1 To SettingAddCheckBoxes

actrow = ActiveCell.RowWith ActiveSheet.CheckBoxes.Add(Selection.Left, Selection.Top, Selection.Width, Selection.Height)

.Width = 80

.LinkedCell = Cells(actrow, 9).Address

End With

ActiveCell.Offset(1, 0).Activate

Next iEnd Sub

Notice variable CBcount. It determines where to add the next checkbox. It’s hard coded to column A (you can change this) in the row of the checkbox count plus 2 (row 1 is header row and we want to go 1 row below the lowest checkbox).

Variable SettingAddCheckBoxes defines how many new checkboxes to add each time you click ‘Add Checkboxes’. It’s a variable stored in named range “SettingAddCheckBoxes” corresponding to cell N1.

The other sub procedures are shorter many using a similar structure like this to loop:

ActiveSheet.CheckBoxes.Select

Dim cb As CheckBox

For Each cb In Sheet2.CheckBoxes

cb.Value = True

Next cb

etc…..

Why did I build this? (I took me hours!). I enjoy building things and sometimes I just can’t get the idea out of my head. Once I build it then it leaves me alone Also, it’s winter and I prefer Excel over joining a bowling league.

I created something similar previously(post). However, I didn’t want to look as building the code from scratch is such good practice.

My name is Kevin Lehrbass. I’m a Data Analyst from Canada.

I love playing around in Excel. Here I proved that I’m only freakishly tall in certain countries.

In this post I made a face move around the screen and interact with cells. It’s my love of Excel, curiosity, long winters and level of caffeine that cause these things to happen. And I’m an introvert most of the time!

]]>

It’s from Wall Street Journal post Why a New Decade Feels Momentous written by Eugenia Cheng, illustrated by Tomasz Walenta.

There’s no practical reason to do this but could I do it? I ended up with this in Excel:

I also created an option to display random numbers and switch back to the original numbers.

My 2019 Post Review Excel file includes the recreated pic and a list of all my posts.

Some were fun (exploring silly ideas when over-caffeinated), others informative (explaining MMULT function), a few compared different solutions and even a couple of chess posts!

**Fun Posts**

I was in the backyard cooking a burger, drinking a beer.

I got inspired to build this!

Auditing Jordan Goldmeier’s hyperlink udf rollover invention!

I also created a mini maze game based on Jordan’s technique.

A face moves using only formulas & conditional formatting.

I also found a way to make the face interact with cells.

It’s surprising how much I learned tinkering around with this

**Informative Posts**

Reviewing a challenge from contextures, explaining MMULT function.

Sharing alternative solutions.

Should we avoid volatile functions?

This debate is just as important as vlookup vs index/match.

**Curiosity Post**

Finally a decent answer to the question:

**Solution Post**

4 solutions to a specific question I had earlier this year.

Which solution do you prefer?

**Power Query**

Power Query is an amazing tool with so many uses.

See how to create all combinations from three tables.

Explore the life changing tool currently called Get & Transform (previously known as Power Query).

**Chess Posts?!**

I review Robert Gascon’s chess game viewer.

Chess and Excel…what could be more exciting?

Robert’s post inspired me to build a FEN viewer!

Given a FEN (text description of chess position) I reposition the pieces on the board.

Download my Excel file above to see the list of all my 2019 posts.

Eugenia’s article was an interesting read. Here’s an excerpt:

Math develops beyond numbers by continuing the process of finding patterns and relationships, and turning them into progressively more abstract concepts. Thinking about numbers leads to equations, which come from relationships between numbers. If we think about relationships between equations, we get into the field of algebraic geometry. Thinking about relationships between whole fields of math leads to my own area of research, category theory.

A similar process gave us the concepts of days and years. Humans discovered patterns in the rate at which the earth rotates and the rate at which it orbits the sun. We then invented a way of organizing time in units that would line up with those cycles in a convenient way. Days and years occur regardless of human observation; the part that we imposed was the arbitrary decision of what would count as the “beginning” of each cycle—midnight and January 1.

**About Eugenia Cheng**

Eugenia is a mathematician. Learn more about Eugenia on her website, WSJ and Wikipedia.

**About Tomasz Walenta**

Tomasz is an illustrator. See his work on Intagram, Marlenaagency and on his site.

Thank you for reading my blog this year. A special thanks to those who commented, offered alternative solutions and provided ideas for posts. A special thanks to Robert Gascon for his insightful comments, post suggestions and Chess Game Viewer.

My name is Kevin Lehrbass. I’m a Data Analyst.

I live in Markham Ontario Canada.

As you can see, I’m a big Microsoft Excel fan!

]]>

It’s cool to see Jordan and Bill Jelen discuss it (video) but I want to know exactly how it works.

Jordan’s UDF rollover Excel file is amazing! Tons of functionality! Let’s examine the basic concept.

I’ll share several Excel files starting with the most basic concept.

Excel file 01 UDF Rollover Basics. File extension is xlsm (macros).

**The Ingredients**

4 items: vba udf code, hyperlink formula, named range and a number.

- add UDF ‘RolloverSquare’ in a vba module
- cell K9 formula =IFERROR(HYPERLINK(RolloverSquare(K100),K100+1),K100+1)
- create named range Xindex in cell K98 (starting value of 0)
- cell K100 contains a number (to be formula later on)

**Let’s Test It!**

Remember: cell K98 is initially set to zero. Now hover your mouse over cell K9.

Voila! Cell K98 now has the value of cell K100+1. We see the behavior. Let’s look at the parts.

**Hyperlink Formula**

To understand it better I simplified it to =HYPERLINK(RolloverSquare(K100))

It results in an error but hovering over it runs the UDF!

**UDF Xindex value?**

Public Function RolloverSquare(XIndex As Integer)

If XIndex <> Range(“XIndex”).Value + 1 Then Range(“XIndex”).Value = XIndex + 1

End Function

What is the value of Xindex above? Where does it come from before If evaluates it?

To answer this I added MsgBox (XIndex) as seen below:

Public Function RolloverSquare(XIndex As Integer)

MsgBox (XIndex)

If XIndex <> Range(“XIndex”).Value + 1 Then Range(“XIndex”).Value = XIndex + 1

End Function

The message box returns 85 from cell K100.

File 02 UDF Rollover shows both values, Xindex named range(K98) and K100, and then changes cell K98.

This also helps to understand the vba If statement:

If XIndex <> Range(“XIndex”).Value + 1 Then Range(“XIndex”).Value = XIndex + 1

The If always returns true and assigns K100 +1 to named range “XIndex” (cell K98).

**Add Rollover Cells**

I added the HYPERLINK function to more cells to see K98’s value change. I removed the Msgbox.

Excel file 03 UDF Rollover (hover cells added) Security settings might turn off the hyperlinks.

Let’s use Jordan’s rollover concept for a mini game (04g UDF Rollover Technique (game)).

Start in the bottom right, navigate the maze and click the WIN button in the top left. Game over if you touch any blue cell.

Add/remove blue hyperlink cells to change the maze. It’s been oddly interesting designing this

(with touch screen you can click WIN right after clicking Start button…where’s the fun in that?)

Let’s review a few more details about Jordan’s amazing PeriodicTable.xlsm

**Element Information**

Sheet ‘Data’ contains the descriptive information for all the elements. Jordan’s concept could be used for dashboards.

**Conditional Formatting**

Various formula based rules add to the look of Jordan’s PeriodicTable.xlsm masterpiece.

**Locking Scroll Area**

When you first open the file you’ll notice that the scroll area is locked. How? In the Visual Basic Editor ‘ThisWorkbook’ (under ‘Microsoft Excel Objects’) contains this:

Private Sub Workbook_Open()

Sheet1.ScrollArea = “$A$1:$W$40”

End Sub

The code above runs every time you open the file. Add apostrophes in front of each line, save, close and reopen so that it won’t run when the file opens allowing you to freely move around the screen.

**More VBA**

‘Sheet 1 (Table)’ and ‘Module1’ below contain vba code worth exploring.

Jordan is a Data Scientist, visualization expert, author and keynote speaker.

See Jordan’s Excel.TV profile to learn more about him. You can also follow him on Twitter and on Facebook(Excel.TV).

My name is Kevin Lehrbass. I’m a Data Analyst.

I live in Markham Ontario Canada. I can contribute a good deal of my technical knowledge to this:

“hmm…that looks interesting. How exactly does it work?”

]]>