(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!

]]>

A UDF is a special kind of VBA. It allows you to create functions! Let’s start with an example.

HereÂ we shared formula solutions to Leila’s challenge: *look for the App in range B5:D45, get column header B4:D4.Â *See how Geraldo’s GetDiv UDF solves this!

Geraldo shared this UDF solution:Â (Download zipped Excel file)

Function GetDiv(LookupVal As String, Titles As Range, SearchArea As Range) As String

GetDiv = Cells(Titles.Row, SearchArea.Find(LookupVal).Column)

End Function

Geraldo’s function used in cell L5:

=GetDiv(H5,$B$4:$D$4,$B$5:$D$45)

His explanation helped me understand:

The function expects 3 parameters GetDiv (

LookupVal,Titles,SearchArea) as below:

1stLookupValÂ is the value we are looking for ($H5 for the first App name)

2ndTitlesis the range where we have the Divisionsâ€™ names: $B$4:$D$4

3rdSearchAreais the area where we’ll look for theLookupVal: $B$5:$D$45

Initially I thought SearchArea was a vba property(it’s a name for where we look for the App).

Now let’s explore further by playing with the code!

This part SearchArea.Find(LookupVal).Column seemed odd so in sheet ‘test Geraldo’s udf‘ I started playing with some vba.

**How does Range.Cells property work?** (SearchArea is a range parameter)

In a basic form it needs two numbers: one for a row, one for a column.

This code assigns a text value to cell E3:

‘provide simple co-ordinates to Cells

Sub Assign_Text_To_A_Cell()

Cells(3, 5).Value = “assign text to a single cell”

End Sub

Cell E3 (row 3, column 5) now has text “assign text to a single cell”.

We could also extract the existing value from a cell:

‘extract the value from a cell and display it in a message box

Sub Extract_and_Display_value()

Dim getvalue As String

getvalue = Cells(9, 3).Value

MsgBox (getvalue)

End Sub

There are many possible applications of Range.Cells! Let’s go back to Geraldo’s code:

Cells(Titles.Row, SearchArea.Find(LookupVal).Column)

Titles.Row is range B4:D4. SearchArea.Find(LookupVal).Column provides a column number so we know which text from B4:D4 to retrieve.

Another way to explainÂ SearchArea.Find(LookupVal).Column is:

In range G16:I18 what is the column number where we find the word “fish”?

This code displays the column number where “fish” is found:

‘Letâ€™s examine syntax: SearchArea.Find(LookupVal).Column from UDF GetDiv

Sub examinesyntax()

Dim LookupVal As String, SearchArea As Range, GetColumnNumber As Integer

LookupVal = â€śfishâ€ť

‘SearchArea = Range(â€śG16:I18â€ť) <â€“wrong syntax. Google search helped to create next line

Set SearchArea = Sheets(â€śtest Geraldoâ€™s udfâ€ť).Range(â€śG16:I18â€ť)

GetColumnNumber = SearchArea.Find(LookupVal).Column

‘Had to google for help with MsgBox syntax

MsgBox (â€śWhat is the column number where we find the word fish?â€ť & vbCrLf & â€śItâ€™s column â€ť & GetColumnNumber & â€ś.â€ť)

End Sub

Building the code really helped me understand SearchArea.Find(LookupVal).Column.

Ready for more vba fun?!

Let’s see how the code behind the right button works (show column number for random item) !

In this case the random word is “orange”.

Rerun to see different random word.

Here’s the code behind the message box:

‘Add more functionality: select random word, show col number

Sub examinesyntaxv2()

Dim LookupVal As String, SearchArea As Range, GetColumnNumber As Integer, Randr As Integer, Randc As Integer, Lookupword As String

Randr = WorksheetFunction.RandBetween(16, 18) ‘random row

Randc = WorksheetFunction.RandBetween(7, 9)Â Â Â ‘random column

Lookupword = Cells(Randr, Randc).Value

‘SearchArea = Range(“G16:I18”) <–wrong syntax. Google search helped to create next line

Set SearchArea = Sheets(“test Geraldo’s udf”).Range(“G16:I18”)

GetColumnNumber = SearchArea.Find(Lookupword).Column

‘Had to google for help with MsgBox syntax

MsgBox (“What is the column number where we find the word ” & Lookupword & “?” & vbCrLf & “It’s column ” & GetColumnNumber & “.”)

End Sub

Now you won’t always get “fish” Notice that vbCrLf creates a carriage return in the MsgBox.

The knowledge doesn’t fall from the sky. I have to practice! Necessity and curiosity (and caffeine) fuel my learning but there’s a lot of tinkering, many google searches for syntax ideas and some grit to get the code just right

By the way…who is Geraldo??? Who is the person behind the GetDiv UDF?

Geraldo is a Data Analyst from SĂŁo Paulo Brazil.

He loves challenges and creating solutions to solve them!

Geraldo has worked in Finance and knows his way around Excel (pivots, formulas, vba), SQL, Cobol, DBase III, VBS, ASP/XML and now the new stuff: Power BI (M, Dax) with Python being his next thing to conquer! An amazing set of skills!

Thanks for the UDF Geraldo and I look forward to learning more from you!

Learn, build stuff, repeat. That’s it! You can learn a lot of vba on your own but there are many tips and nuances that you can learn from a professional. More structured learning often helps get past certain hurdles.

How you learn is up to you (books, videos, etc). Here are some suggestions:

- Paul Kelley’s website
- Leila Gharani’s YouTube channel
- Jon Acampora’s How to write a UDF
- Dan Strong’s YouTube channel
- Dinesh Kumar Takyar’s YouTube channel
- Sumit Bansal’s Guide to creating a UDF

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

I often spend hours playing with Microsoft Excel but eventually a few things happen:

- My dogs get mad at me (they want to play)
- I need more coffee
- There’s a strange pain in my stomach. Oh yeah…food.

I have two wonderful dogs Cali and Fenton. Here you see Cali demanding that I take a break from the spreadsheet. We’ll go play in the backyard for awhile and then read a book (Excel or Power BI) on the couch

]]>

1)**Kevin’s FEN viewer basic**,Â 2)**Kevins-FEN-viewer-plus-v3**Â (database, FEN explanation).

Given this FEN text…

r6k/2R5/6R1/pp1Ppp2/8/Pn2B1Pr/4KP2/8 w – – 0 1

…we can create this chess position:

A FEN is split into 8 parts separated by “/”. Each part is a row on a chess board.

**“r6k” **describes row 8 at the top. Let’s examine each item:

- lowercase “
**r**” = black rook (top left a8), - number “
**6**” = 6 consecutive blanks squares - lowercase “
**k**” = black King (top right h8)

**“****2R5****”Â **describes row 7.

- number “
**2**” = blank squares (a7 & b7) - uppercase “
**R**” = white rook - number “
**5**” = 5 blank spaces

Near the end the “**w**” indicates that it’s white’s move.

Here we see each row’s FEN code:

Robert Gascon’s ‘**Excel Chess Games Viewer**‘ inspired me to create this FEN viewer two weeks ago. I used 6 steps spread across 42 columns.

Unhide columns to see the formulas:

- on the ribbon select View and check Headings
- select columns N to BI
- right click & unhide

Steps start in column P and move to the right:

Step 1 splits FEN r6k/2R5/6R1/pp1Ppp2/8/Pn2B1Pr/4KP2/8 out per row in column P

Note: each number = consecutive blank squares. Step 6 has 8 cells representing each square in a chess row. ** A FEN is compact. My idea? Spread the FEN over 8 squares of a chess row**.

“r6k” becomes “r666666k”. “2R5″ becomes “22R55555”Â (step 6 in column AX). Audit formulas in all steps to understand fully.

On the chess board look at cell C7 array formula:

=IFERROR(INDEX($BH$7:$BH$19,MATCH(TRUE,EXACT(AX7,$BG$7:$BG$19),0)),””)

Cell C7 looks for AX7 value “r” in column BG. The answer is a chess icon from column BH.

A couple of important parts of the formula:

- “r” is different from “R” so I used MATCH(TRUE,EXACT(
- I used IFERROR (Numbers are blank squares. There’s nothing to display.)

A good summary from Wikipedia:

FEN is based on a system developed byÂ ScottishÂ newspaper journalistÂ David Forsyth. Forsyth’s system became popular in the 19th century; Steven J. Edwards extended it to support use by computers. FEN is an integral part of theÂ Portable Game NotationÂ for chess games, since FEN is used to define initial positions other than the standard one. FEN does not provide sufficient information to decide whether aÂ drawÂ byÂ threefold repetitionÂ may be legally claimed or aÂ draw offerÂ may be accepted; for that, a different format such asÂ Extended Position DescriptionÂ is needed.

- Excel formula calculates value ofÂ Chess pieces
- Robert Gascon’s Chess game viewer
- Diarmuid Early’s Chess game viewer
- Daniel Ferry’s Chess game viewer
- Pedro Wave’s Chess board PGN viewer

- Amazing Videos from Agadmator YouTube Chess Channel
- Play and learn chess: www.chess.com
- Study chess tactics (online or via book)
- Chess phone apps (i.e. ‘Chess Time’, ‘Shredder Chess’, ‘Chess Tactics Pro’)

FEN examples fromÂ ‘Kevin’s FEN viewer plus v3’:

- Row 16 agadmator: find the next move (Carlsen vs Anand)

Agadmator sometimes asks us to pause the video and find the best next move.

Subscribe to his YouTube channel! You will learn a lot.

- Row 17 my game: find the mate combo! (black’s move)

Use my Excel file to collect your FENs.

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

I know….two chess related Excel posts in a week is a bit too much for most. But some of us love both so why not?

]]>

Canada uses humidex calculation while the U.S. uses HeatIndex.

HumidexÂ (short forÂhumidity index) is an index number used by Canadian meteorologistsÂ to describe how hot the weather feels to the average person, by combining the effect of heat andÂ humidity

The

heat indexÂ (HI) orÂhumitureis an index that combines air temperature andÂ relative humidity, in shaded areas, to posit a human-perceived equivalent temperature, as how hot it would feel if theÂ humidityÂ were some other value in the shade.

I found what appears to be the common formulas for Humidex & HeatIndex.

Let’s start with **Humidex formula**. You’ve seen a heat advisory but a formula advisory?

This formula is extremely long and tedious to read. It may cause dizziness, exhaustion, confusion, etc. Seek professional help if you feel any of these symptoms.

By entering a few carriage returns we can isolate each nested IF. It’s a bit easier to read.

Upon further examination I noticed that this part repeats several times:

(((-42.379+2.04901523*D4+10.14333127*C4-0.22475541*D4*C4-0.00683783*D4*D4-0.05481717*C4*C4+0.00122874*D4*D4*C4+0.00085282*D4*C4*C4-0.00000199*D4*D4*C4*C4)-32)*5/9)

I put it in a named range called ‘hx’. I also created named range ‘cnvt’ to convert Celsius to Fahrenheit.

**The humidex formula below is now much easier to read!**

You’ll have to also audit the named ranges but it’s worth it!

Now let’s look at the **HeatIndex formula**.

This is from **Dick Kusleika’s Excel site.** I can’t think of a way to make this easier to read, can you?

I definitely agree with Dick’s point below!

People have been complaining about the excessive heat for a week around here. Not me. It wonâ€™t be long until Iâ€™m shoveling my driveway, so Iâ€™m counting my blessings.

I’ve enjoyed this warm summer. Today (Aug 10) had a high of 23C, 41% humidity and a cool breeze (much cooler than most days in July!)

After summer is nice fall weather. Then in the winter we will be complaining about the wind chill factor (maybe I’ll calculate that too!) and dreaming of hot summer days!

* What is your definition of heat?* Many from the north of Canada consider southern Ontario summers to be unbearable. But those of you from warm climates would laugh at us in Canada. But then again if you visited Canada in the middle of our winter you would be in shock and we would know what to do

The overall “how we feel” calculations have different variations. Also, we all experience heat differently depending on our tolerance (i.e. health, age), intensity of our outdoor activities, etc.

Here’s some **interesting info** regarding working outside in the heat (Canadian government). My Excel file has various related links.

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

Right now it’s summer and it’s been hot (several 30C + days).

Our climate varies a tremendous amount from winter to summer. During winter the temperature can go all the way down to -30C (I live in the southern warmer part of Canada!) but usually it’s between 5C and -20C.

In winter we have to clear our driveways (or pay someone) but the city clears the roads and sidewalks. In Markham we don’t have to shovel the roof of the house but apparently in some parts of Canada that’s necessary. Here the temperature rises enough to periodically melt the snow on the roof.

I’m going to enjoy the last part of summer being in my backyard without putting on a coat or shoes!

]]>