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?”

]]>

Duplicate Dataset Formula Challenge (contextures.com).xlsx (I added to original contextures.com file).

In this post I will:

- review Contextures MMULT challenge & solutions
- explain reasons for not using MMULT
- share my non MMULT solutions
- explain MMULT in a unique way

Find Duplicate Sets challenge from Contextures Nov 26 newsletter:

…how to count duplicate number sets. They had hundreds of rows, with 6 numbers in each row (yes, they were lottery results!) How many times was each number set in the list, in any order?

Rows 4 and 6 have the same numbers.

Debra’s MMULT array formula (enter with Control Shift Enter):

=SUM(IF(MMULT({1,1,1,1,1,1},TRANSPOSE(COUNTIF(B2:G2,$B$2:$G$12)))=6,1))

Robert Gascon emailed me his non array formula:

=SUM(–(MMULT(COUNTIF($B2:$G2,$B$2:$G$12),{1;1;1;1;1;1})=6))

Both are brilliant compact formulas but are challenging to understand and explain for most people.

Robert challenged me to create a non array solution. I created two solutions but both have >1 step.

**MMULT is a magical function! What’s the problem?**

A) Explaining how it works

I create solutions that people need to use and modify. MMULT is a complex function that is challenging to explain. Even if I can explain it well, many Excel users will forget how it works and struggle to modify it.

B) Time to solve

If I’m helping someone that only has a few minutes then I can often find a quicker way to solve it. Probably not as efficient and compact as MMULT but there’s not always time to create the optimal formula. Sometimes practicality beats perfection.

* How would I solve it?* I have 2 solutions. Step by step and fancy textjoin.

My step by step solution:

- 6 helper columns to extract numbers in order =SMALL($B4:$G4,1)
- concatenate the numbers =TEXTJOIN(“,”,TRUE,$H4:$M4)
- simple countif =COUNTIF($N$4:$N$14,$N4)

This solution splits the complexity into smaller bits but there are many more steps required.

My fancy textjoin solution:

- sort and join =TEXTJOIN(“,”,TRUE,SMALL($B4:$G4,{1,2,3,4,5,6}))
- count them =COUNTIF($H$4:$H$14,$H4)

This solution requires careful explanation. The SMALL($B4:$G4,{1,2,3,4,5,6}) part sorts the numbers! The {1,2,3,4,5,6} is an array constant (SMALL normally only gets 1 value but we want 6). Another reason to explore alternative solutions was that Debra & Robert already hit grand slams with their MMULT formulas! All the steps I’ve done above are neatly included in their shorter single MMULT based formula.

Most explanations start with “it’s matrix multiplication like algebra” …and the audience is lost. It helps to see what happens cell by cell. Sheet ‘MMULT explained’ has a detailed explanation.

Let’s change values of array 1 to see how it affects the MMULT results (green area).

Array 1 is all zeros.

Array 2 has unique numbers.

MMULT output is all zeros.

Change cell E3 to 1.

MMULT top row = array 2 top row.

Cells E3 & F3 = 1.

MMULT top row = sum of array 2 top 2 rows.

Cells E3 & F3 & G3 all = 1.

MMULT top row = sum of array 2 top 3 rows.

The 24 in cell N10 = 1 X 7 + 1 X 8 + 1 X 9

The 33 in cell O10 = 1 X 10 + 1 X 11 + 1 X 12

etc. ….and you can do the same with cells E4, F4, G4.

Check the boxes to reveal step by step explanation:

Instead of an hour of reading I prefer to learn the basics and then play around. I can always go back later and read further details.

You’ll hopefully now be more comfortable with how MMULT works. Granted, the MMULT solutions by Debra and Robert are more complex (and brilliant!) but we’ve made progress. Audit their formulas using F9 key.

Debra is the owner of Contextures.com Millions of us have learned Excel by reading her Excel blog and her books. Debra was one of the first Excel MVPs. I also enjoy her Excel newsletter. There’s always something to learn. Debra lives west of Toronto and I live north east of Toronto.

Robert is a Certified Public Accountant from Quezon City, Philippines. Robert is a valued contributor of the Microsoft tech community. See his profile. He believes in building super efficient non volatile formula solutions. I’ve learned a lot from Robert this year. Besides data, Robert and I are both chess nerds.

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

I live in Markham Ontario Cnada.

Learning Excel does require a lot of hard work but it’s also intriguing, challenging and fun

]]>(my finished Excel file)

Using only conditional formatting and formulas make this face move around an Excel sheet and interact with cells containing numbers.

(my previous post used vba to move around)

**Default Eye Position**

- left eye: row 9 (cell N103), column 6 (cell P103)
- right eye: row 9 (cell N104), column 11 (cell P104)

**Adjusting Default Eye Position**

Clicking the arrow buttons assigns numbers to cells F102 and J102. Formulas in the green area adjust the starting point values based on the arrow button values.

**Make the Eyes Move!**

These conditional formatting rules are the final step to make the eyes move!

- =AND(ROW(A1)=$S$103,COLUMN(A1)=$W$103)
- =AND(ROW(A1)=$S$104,COLUMN(A1)=$W$104)

Change blue eye color to brown or green if you wish.

**Excel File Moving Eyes**

Click the arrows to see the eyes move! See how it works in this Excel file.

Repeating the same steps we add Mouth, Hair, Sideburn left, Sideburn right, Nose and Face.

Now we can move the completed face using the arrows keys.

Challenge: **trigger an action based on the face touching any cell with a number.**

Concept: I ended up using formula based intersection method. Not easy but it worked!

**Face Named Range**

Here’s the dynamic named range for the moving face:

=OFFSET(Sheet1!$A$1,Sheet1!$AC$115-1,Sheet1!$AG$115-1,Sheet1!$S$115,Sheet1!$V$115)

**List All Cells With Numbers**

If I simply hard coded cell references to match cells with numbers then this works:

=SUM(I17 face)

This uses intersect method to determine if cell I17 and named range face intersect. As cell I17 would have a number in it I can further test if this intersection is >0.

But isn’t that lame? I want to allow you to add/remove cells with numbers.

Solution: I used a multi column approach to solve this in rows 126 to 141. You can enter numbers in 15 different cells. The message box lets you know whether or not the face intersects a cell with a number.

It works! The face interacts with cells that contain a number. The message box is basic but it proves that it’s possible!

This is not very practical but it was a fun challenge and great practice!

99% of Excel users have no idea how powerful Excel is. Curiosity and determination enable creative solutions in Excel.

You could possibly create a quiz in Excel using this method. Cells could be different categories and intersecting a cell could display a random question from that category.

Of course I kept playing around with this. Now the message box also displays the number from the intersecting cell.

Earlier I mentioned curiousity and determination. I forgot to mention that I broke one of my golden rules: no coffee after 4 pm!

I’m a Data Analyst and Excel enthusiast.

I live in Markham Ontario Canada (near Toronto).

Outside of Excel I enjoy hanging out with my dogs Cali and Fenton.

]]>(Excel file found below using VBA. Read instructions carefully before using)

The Space Invader logo was my inspiration for this mini game. Memories of early 1980s computer games passed through my mind while I waited for my burger to cook.

I came up with the idea of making a character move around the screen to capture the beer logos.

“

How would the character move?“

This is our hero who needs to collect beer in order to celebrate Spreadsheet Day with his friends!

He needs to collect beer in a timely manner while avoiding nasty beer!

I had never used the VBA OnKey syntax. I figured this was a great time to use it! OnKey changes the behavior of the keyboard. I used it to assign macros to the arrow keys.

Sub TurnOnArrows()

Application.OnKey “{RIGHT}”, “MoveR”

Application.OnKey “{LEFT}”, “MoveL”

Application.OnKey “{Down}”, “MoveD”

Application.OnKey “{UP}”, “MoveU”

End Sub

I attached a simple action to “MoveR” and the others to ensure that it was working.

NOTE: in the file I have carefully documented how to return to the keyboard’s default behavior (so arrows won’t run the macros). There are two automatic ways and also a manual button.

This is the code that restores the default arrow behavior:

Sub TurnOnArrows()

Application.OnKey “{RIGHT}”

Application.OnKey “{LEFT}”

Application.OnKey “{Down}”

Application.OnKey “{UP}”

End Sub

After experimenting I settled on combining Selection.Cut with ActiveCell.Offset(0, rightvalue).Activate and Selection.Paste to make him move around the screen.

rightvalue is a variable but it made the most sense to move him 8 squares each time an arrow key was pressed (character is 8X8).

So finally….I was able to press the arrows and move him! Cool!

I had a vague memory of the VBA intersect method. It took a LONG time to get the code just right.

For each arrow click I had to check if the character intersected with the placement of the four beers.

Set me_beer = Application.Intersect(Range(“

me”), Range(“grid!$AZ$14:$BH$27, grid!$BX$32:$CD$43,grid!$W$46: $AE$59,grid!$AW$51:$BC$62″))

This checks if named range me intersects with any beer in sheet grid. Beautiful

If there’s no intersection then simply move him in the direction of the clicked arrow key.

If there is intersection (meaning he grabs a beer) then increase the beer score! Yes, I created a way to track the beers collected and subtract points for touching nasty bad beer (don’t buy cheap beer for your friends on Spreadsheet Day!). Check out sheet ‘stats’. A perfect score is 36.

Check out sheet ‘stats’. A perfect score is 36. How fast can you collect your beer and share it with your friends? Can you get 36 points in less than 30 seconds?

My exciting Excel Beer Game v3.0 should entertain you for 1 or 2 minutes. Please save and close all other Excel files before opening my Excel file.

Yes it’s a bit lame but the point is to make learning fun! Now I know how to use intersect and onkey!

Maybe I could make the Space Invaders move around a bit. It would be harder to capture them! Or what about customizing the character’s features? That seems possible but I ran out of time. Maybe for the next version!

Here are some beer companies from Ontario Canada. Great variety and taste:

- https://www.refinedfool.com/
- https://www.rougeriverbrewingcompany.com/
- https://www.amsterdambeer.com/

I’m not getting paid to say that their beer is great but if you want to send me some free swag or beer that would be fantastic!

I remember the classic games from the early 1980s. Sometimes we would change the code for games on the TRS80.

In 7th grade we were given computer time on the Vic20. I had this funny idea to change some code and output a message about our principal Mr. Durfy. Fortunately I didn’t use any bad words because just as I ran the code I realized that he was right behind me looking over my shoulder. Man….I was so lucky that he found it amusing!

]]>

Numbers describe height, intelligence and tests. How do we compare these numbers to others?

- Tim is 2 meters tall! That’s extremely tall!
- Sonja’s IQ is 117. She’s a genius!
- I got 76% on the test. Not bad.

We’ll use height. Normal Distribution & Standard Deviation allow us to compare height.

It’s easier to visualize than test scores or IQ. In a crowd you compare the height of those around you. Internally you do the math.

Bill Jelen (Mr Excel) and I in 2015.

Bill is 6 feet 1 inch (185 cm). I am 6 feet 4 inches (194 cm).

Instead of using adjectives to describe our height we’ll use standard deviations.

**What do height, I.Q. and test scores have in common?** All are normally distributed.

Chart below shows: most are close to the mean(average), half are above the mean and half are below.

Some are taller (to the right) or shorter (to the left). Very few are extremely tall or short.

In the U.S. average male height is 5 feet 9.3 inches (69.3 inches, 176 cm). source

Left and right sides of the chart are symmetric. Normally distributed data-sets share this symmetry but the spread varies. Values may cluster around the mean or be more spread out. Standard deviation measures this. Normal distribution is also known as Gaussian distribution and the bell curve.

Measures the spread of the numbers from the average (mean) in normally distributed data-sets.

- 68.27% of values are within one standard deviation of the mean.
- 95.45% of values are within two standard deviation of the mean.
- 99.73% of values are within three standard deviation of the mean.

It works for all normally distributed data-sets. In statistics this is known as the empirical rule.

Data clusters closer to the mean as standard deviation decreases. The empirical rule still works.

For U.S. male height 1 standard deviation = 2.94 inches (7.5 cm). Let’s explore this in Excel!

In sheet ‘INPUTS & DATA’ I created a sample date-set using:

- mean male height of 5 feet 9.3 inches (69.3 inches, 176 cm)
- standard deviation of 2.94 inches (7.5 cm)
- formula in column E =NORM.INV(RAND(), 69.3, 2.94) (pasted as values)

Below we see the sample of 30000 produced results very close to the empirical rule.

- 20510 (68.37%) within 1 stand dev of mean (66.37 to 72.24 inches, 68.57 to 183.49 cm)
- 28618 (95.39%) within 2 stand dev of mean (63.43 to 75.18 inches, 61.11 to 190.95 cm)
- 29932 (99.77%) within 3 stand dev of mean (60.49 to 78.11 inches, 53.65 to 198.41 cm)

Displayed using feet and inches:

- 68.37% are between 5 feet 6 inches and 6 feet 0 inches.
- 95.39% are between 5 feet 3.4 inches and 6 feet 3.2 inches.
- 99.77% are between 5 feet 0 inches and 6 feet 6 inches.

Bill’s 1.26 standard deviation is between the 1st & 2nd deviation above the mean.

My 2.38 standard deviation is between the 2nd & 3rd deviation above the mean.

Men above 6 feet 6 inches (past 3rd standard deviation) are extremely tall. Kevin Durant is 6 feet 11 inches with a standard deviation of 4.7

This entire post I’ve been referring to male height in the United States.

**What if Bill and I were to travel to Bolivia? Would we be taller?**

Of course not but we’d be perceived as being taller by the local people! In Bolivia my height would put me 4.5 standard deviations above the 5 feet 3 inch mean (2.92 inch SD). Bill would be 3.4 standard deviations above the mean. If we traveled to The Netherlands my standard deviation would be 1.7 and Bill’s would be 0.6. We would blend in quietly. Isn’t that weird?

If a data-set is perfectly symmetrical (left side of chart is exactly like right side) the skew is zero.

Our sample of 30000 gave us a skew of 0.00561 Closer to zero means more symmetrical.

In sheet ‘STATS’ row 26 I calculate the skew for various small samples.

- skew = -0.6108 (10 rows of sample data)
- skew = -0.1818 (100 rows of sample data)
- skew = -0.0972 (1000 rows of sample data)
- skew = 0.0072 (10000 rows of sample data)

The skew decreases as we include more data! If a data-set is truly normally distributed the skew approaches zero as the sample increases.

In sheet ‘STATS’ rows 23 & 24 we see the mean and median values for the small samples. Row 25 shows that the absolute difference decreases as we include more sample data!

The mean and median values get closer and closer as we increase the sample size.

- 0.832 absolute difference (10 rows of sample data)
- 0.169 absolute difference (100 rows of sample data)
- 0.041 absolute difference (1000 rows of sample data)
- 0.026 absolute difference (10000 rows of sample data)

Horizontal axis labels are linked to cells I14:I22 (sheet STANDARD DEVIATION CHART).

To get the right look and functionality I used three chart tricks.

(1) They weren’t displaying properly (text was jammed together)

To fix this I forced two carriage returns using the CHAR function. Character 10 does the magic. Now the text displays nicely in three lines.

(2) I wanted a way to easily switch between metric and imperial

I added a check box (check = metric, uncheck = imperial) and used the TRUE FALSE in the formula.

(3) I only wanted to display the integer (not all the decimals)

I used the TEXT function to format the number. I also could have used the FLOOR function.

The end formula is a bit long but it gets the job done:

=IF(H13=0,””,IF(H13=1,”man “,”men “)&CHAR(10)&IF($J$12,TEXT(F12,0)&” to “&TEXT(F13,0)&CHAR(10)&” inches”,TEXT(G12,0)&” to “&TEXT(G13,0)&CHAR(10)&” cm”))

Download my Excel file. There are 5 sheets:

- INPUTS & DATA enter parameters to create data-set
- PIVOT TABLE & CHART summarize & visualize
- STANDARD DEVIATION CHART visualize by standard deviations
- STATS additional statistics
- HEIGHT EXAMPLES used in this post

To see how to create the sample data you can replace the pasted values in column E sheet INPUTS & DATA) with formula =NORM.INV(RAND(), $B$5, $B$8)

There’s so much more to learn! Here are some interesting www links:

- Investopedia’s Normal Distribution explanation.
- Interesting articles and calculators at Tall.Life.com
- KhanAcademy NormalDistributionIntro and Excel file.
- How tall is tall discussion at Quora.
- Advanced statistics from statisticsbyjim

Here’s an interesting video from Oz du Soleil. The first part is about estimating my height.

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

Normal stores rarely sell my pant size. L.L. Bean’s catalog used to have my size but not any more. Big & Tall stores say “we don’t have that small size” or they do but a single pair costs a fortune.

That day I did find my size and there was a sale! I bought all the pairs they had in stock!

]]>