Tiger Solutions/Excel (VBA) For Football Traders - Heatmaps Season 2

  • £100

Excel (VBA) For Football Traders - Heatmaps Season 2

  • Course
  • 27 Lessons

Contents

SESSION 1: A Blueprint

The starting point for season 2 of the Heatmaps series is … Heatmaps – season 1!  We begin by revisiting the output from Heatmaps season 1 and noting how we might improve on it.  The basic idea is to use the power of VBA to create a more sophisticated analysis that looks both at odds brackets and another variable of interest – teams or leagues, for example.

In this session, we discuss the importance of a ‘blueprint’ – a visualization of the analysis you intend to create.  In the video, I create the layout for the heatmap - including the teams and odds brackets – and add some helpful formatting.  Just visualizing the output in this way can be motivational and certain gives a sense of where we’re going – this is the point of a blueprint.  Make sure you do something similar when starting any Excel project, even with pen and paper.

So, we have an idea of the destination, but what about the journey?  What calculations are required to get the analysis we need?  See you for the all-important planning and conceptualization phase in the next video.

Topics And Techniques
  • Creating a ‘blueprint’ – visualizing the analysis you need
  • Basic layout for heatmap
  • Use UNIQUE to extract unique values from a dataset
  • How to delete a named range
  • Dynamic range formulae and #SPILL! Errors
  • Quickly format a tabulated analysis
  • Create conditional formatting for a ‘heatmap’ effect
  • RANDBETWEEN and RAND formulae to generate random data
  • VBA vs. Formulae vs. Pivot Tables for this task: pros and cons
Heatmaps S2 V1.mp4
Heatmaps S2 V1 Start.xlsm
Heatmaps S2 V1 End.xlsm

SESSION 2: Planning And Conceptualisation

Pseudo-coding is the practice of writing out in human language what a computer programme (ie. a ‘macro’ in Excel) should do.  I love it because it’s a ‘conceptual’ exercise - you can do it without any knowledge of VBA at all, though some knowledge would certainly help.  The purpose is to make clear the logic you wish to follow, and create a set of instructions that can easily be translated (later) into code.

It also forces you to think in a practical sense how the macro would actually work.  In the video, I build up pseudo-code for the heatmap generation routine, encountering a number of conceptual coding challenges along the way.  Should we ‘modulate’ out chunks of code that might be useful for other routines, for example?  What named ranges or anchor points should we use?  Would it be better to use numbers or letters to refer to columns …?

Dealing with these important questions when you’re not knee-deep in a coding language is definitely advantageous!  The output from the session is a route map that should keep us on track as we begin to build up the code – we’ll start that in the next session.

Topics And Techniques
  • What’s Pseudo-Code?
  • Insert a module in the VBA Editor
  • Importance Of Option Explicit
  • How to write pseudo-code step-by-step
  • When to ‘modulate’ code into a separate macro
  • How to build flexibility into a spreadsheet
  • How to create a named range and why to use named ranges
  • How and why to add an ‘Engine’ sheet
  • Advantage of using numbers (rather than letters) to reference columns
Heatmaps S2 V2.mp4
Heatmaps S2 V2 End.xlsm
Heatmaps S2 V2 Start.xlsm

SESSION 3: Dynamic Definition Of Data Ranges 1

What greets us in the VBA editor at the start of session 3 is a lot of pseudo-code!  It’s a great start – but now the question is, ‘how should we begin the process of translation to Excel VBA?’  Yes, it would be possible to simply begin at the top of the VBA editor, dealing with problems as they arise.  

It’s more efficient, and better for your sanity, however, to identify the most used elements of the coding, and to start there.  Of all the small macros we’ve mapped out, which will be used most often?   One such macro concerns defining the size of our heatmap – since without knowing its size, we can’t clear it, format it or do anything else useful.  So, it makes sense to start there with a dynamic range definition.  Let’s get to it!

In the video, I demonstrate how to dynamically define a dataset range with Excel VBA.  Yes, we’ve done this before on Excel VBA for Football Traders, but never in this level of detail.  I show you two possible approaches – ‘top-down’ and ‘bottom-up’, discuss the pros / cons of each and reveal which I use on my real-world VBA projects.

We also cover how to deal with ‘corner cases’ – tricky situations that seldom occur but cause the code to crash when they do!  One such case is when there’s no data in the dataset.  How to build resilience into the code to account for this?  This is a sign of a professional-level VBA application – all possible scenarios have been anticipated, creating a robust file that’s slick, smooth and reliable.

Topics And Techniques
  • How to translate pseudo-code into VBA
  • Macro to dynamically define dataset size
  • Working with integer and string variables in VBA
  • Using a sting variable to store dataset size
  • What is ‘dynamic quality’?
  • Why VBA is like going to the gym!
  • Dealing with situations where there’s no data
  • If – Else – End if statement
  • ‘Stepping through’ VBA code to test it
  • ‘Top-down’ vs. ‘Bottom-up’ approach for range definition
  • Range(range,range) technique
  • .End(xldown) / .End(xlup)
  • Overflow VBA error
Heatmaps S2 V3.mp4
Heatmaps S2 V3 Start.xlsm
Heatmaps S2 V3 End.xlsm

SESSION 4: Dynamic Definition Of Data Ranges 2

A continuation of session 3, session 4 is also concerned with dynamic range definition.  These high-level coding techniques involve Excel VBA’s most powerful pieces of syntax and, as I demonstrate in the video, are tricky to put together!  A lot of testing, tweaking and interpretation of VBA’s error messages is needed.

As I explain in the video, however, we are definitely ‘front-loading’ this heatmaps project.  In other words, by dealing with the complicated coding structures now, things will come together quickly later.  I promise!

Topics And Techniques
  • String variable to dynamically define address of dataset
  • Range(range,range) concept
  • With .. End With to simplify code
  • VBA error 1004 – what it is and how to avoid it
  • Testing code (and dealing with unexpected outcomes!)
  • Testing the ‘no data’ scenario
  • How many columns are in a spreadsheet?
  • .End(xltoright)
  • Using Msgbox to test VBA code
  • Using the Name Manager in Excel
  • Named range naming conventions
  • Get to the punch-the-air moment!

Heatmaps S2 V4.mp4
Heatmaps S2 V4 Start.xlsm
Heatmaps S2 V4 End.xlsm

SESSION 5: Create A List Of Unique Values With VBA 1

Being able to create a unique list of values is an essential skill for any football trader working with Excel.  Whether you need team information, leagues or something else, the ability to ‘remove duplicates’ is important.  These days, Excel offers us a few options, including the UNIQUE formula available in Excel 365.  At the start of the video, I demonstrate the UNIQUE formula and discuss some of its pros and cons.  But, this being Heatmaps season 2, we’re going with a VBA-based solution.  So, let’s get into that!

Getting into the VBA editor, our first job is to ‘promote’ a variable from routine to module level.  This allows the variable to pass its value from one macro to another and facilitates the ‘modulated’ approach we’re trying to implement in this series.  Rather than having to re-write complicated VBA code, we can now simply run another macro in the module to get the range definitions we need – the principle of modulation in action!

Though our aim, eventually, is to create a unique list of team names, some preparation is required.  Which is why, in the video, I deal with (yet another!) dynamic range definition, this time of the home team column on the data sheet.  Yes, we’ve been doing a lot of dynamic range definitions!  Perhaps too many.  But, that’s part of the VBA ‘maximalist’ approach and, once they are all defined, you can move onto the tasks that will really add value.  As I have explained more than once in this series, the best approach to VBA projects is usually to ‘front-load’ the heavy coding, as we are doing in these videos. Onwards!

Topics and Techniques

  • Excel UNIQUE formula

  • A modulated coding approach

  • Concept of ‘Scope’ applied to named ranges and variables in Excel

  • ‘Promoting’ a variable to module level

  • .Clear vs. .ClearContents in VBA

  • More dynamic range definition!

  • Using a breakpoint in the VBA editor

  • Storing important values in the Engine sheet

  • For-Next loop to loop through all teams

Heatmaps S2 V5.mp4
Heatmaps S2 V5 Start.xlsm
Heatmaps S2 V5 End.xlsm

SESSION 6: Create A Unique List Of Values With VBA 2

In this session, we complete the task of building a unique list of values using Excel VBA.  With the main coding structures (a macro with variables and loops) in place after session 5, it’s time to implement the sophisticated code to bring everything together.  This will be challenging so, as always, let’s take it step-by-step - with testing at each stage.

I first undertake an ‘easy’ (!) task to get things moving in the right direction.  The ability to move (or ‘transfer’) data around a file is a great strength of Excel VBA, and the simple a=b concept (where ‘a’ is the destination and ‘b’ the origin) is all you need to get started.  I implement a simple line of code for us to build on.

Next, it’s time to move to a higher level of sophistication.  In this case, this means ‘conditionality’ – a function to add a team to the bottom of the list, but only if it’s not already in the list.  That’s the logic, and it’s important to articulate it clearly – I always speak it out loud.  With the logic clear, we can select a technique – and the combination of application.worksheetfunction  and COUNTIF is perfect for the job.  The addition of offset means teams are always added to the bottom of the list in ‘dynamic’ fashion.  Powerful stuff!

Finally, how to sort this unique list of teams?  Since it’s logical to display them in alphabetical order.  This requirement leads to a discussion about the three sources of VBA code and the application of a brilliant facility in Excel – the macro recorder.  I demonstrate how to use the macro recorder to generate code, then subsequently tweak and integrate it into the main routine to get the job done.  Onwards!

Topics and Techniques

  • Transfer data with an a=b operation in Excel VBA

  • A conditional statement with IF

  • The syntax of IF statements in Excel VBA

  • Using Compile in the VBA editor to check syntax

  • Application.worksheetfunction with COUNTIF

  • Add a value to the bottom of a list dynamically with offset and a variable

  • Running a big test – VBA showboating!

  • Testing for dynamic quality in VBA

  • How to sort data with Excel VBA

  • The 3 sources of VBA code – organic, recycled, recorded

  • Using the macro recorder

  • Tweaking and refining recorded code in the VBA editor

  • Integrating recorded code into the main routine

  • A schoolboy error (don’t try this at home!)

Heatmaps S2 V6.mp4
Heatmaps S2 V6 Start.xlsm
Heatmaps S2 V6 End.xlsm

SESSION 7: The Unique Power Of The Do-Until Loop In Excel VBA

Do you absolutely need to know do-until loops to get things done in Excel VBA?  Well, no.  In fact, 95% of jobs can be done with the simpler loop types we’ve seen many times in Excel (VBA) for Football Traders: for each and for next.  However, as I demonstrate in the video, do until does present new and intriguing possibilities.  This session should help you appreciate the unique benefit of do until and understand how it might fit into your Excel tool kit.

In terms of practical application, the video focuses on the creation of odds brackets – the other (horizontal) axis in our heatmap table.  Odds brackets are a basic analysis for any football trader, so being able to create these analyses quickly is a must.  Not only that, with VBA you can analyse any number of odds brackets – of any size – at the click of a button.

In the video, I work through the tricky logic of the do-until loop.  To give maximum flexibility to the user in terms of odds brackets generation, the macro must account for user inputs for the minimum and maximum values in the odds range, and the size of each bracket.  This is all possible, but requires a step-by-step approach and (optionally) lots of variables!  We get the job done with the usual steady-and-systematic method, enjoying a minor ‘punch-the-air’ moment at the end of the session when the do-until loop works its magic …

Topics And Techniques

  • Simple one-line conditional statement in Excel VBA

  • ‘Promoting’ a variable to module level

  • The advantage of using variables: principle of portability

  • Integer vs. double variables for storing numbers

  • Importance of ‘initialising’ variables

  • Managing named ranges with the name manager

  • Getting started with a do-until loop

  • Using a condition to exit a do-until loop

  • Do until vs. loop until

  • Testing a do-until loop

  • Incrementing a variable with a = a + 1

  • Another example of offset working within a loop

  • A minor punch-the-air moment!

Heatmaps S2 V7.mp4
Heatmaps S2 V7 Start.xlsm
Heatmaps S2 V7 End.xlsm

SESSION 8: Dynamic Formatting With Excel VBA

If you’ve invested time getting your Excel VBA application to work (and why not?) then you might also want it to look good.  VBA can do most jobs in Excel (though it shouldn’t be applied to everything) included making your spreadsheet look appealing.  And don’t worry, we’re not going to simply record reams of code in the macro recorder; rather, we’ll explore the technique I use in my VBA applications to get exactly the appearance I need – every time.

My technique involves ‘storing’ formats on a supporting sheet.  I use a ‘Format Store’ sheet, these days, as a generic sheet for this purpose.  But, given the Engine sheet isn’t too busy at the moment – we can use it for this job.  The beauty of using a format store is you can create any format and simply copy into the range where you need that formatting.  So, changes can be made quickly and easily in the spreadsheet with no need to access the VBA editor – cool!

In the video, I talk you through the process, step-by-step.  As you will see, the coding requirement is relatively light.  And, given that it offers total flexibility for the appearance of the spreadsheet, this session is well worth a look.

Topics And Techniques

  • Concept of a ‘format store’

  • Generic sheet roles – a ‘format store’ sheet?

  • Role of the conditional formatting rules manager

  • Basic Excel colour scheme ideas

  • Named range naming conventions

  • How to copy / paste special with Excel VBA

  • Exiting cut-copy mode with Excel VBA

  • .Clear vs. .Clearcontents in Excel VBA

  • Using breakpoints to debug VBA code

  • Using Ctrl + Enter to autofill variable names

  • My million-pound Excel VBA application!

Heatmaps S2 V8 Start.xlsm
Heatmaps S2 V8 End.xlsm
Heatmaps 8 Final.mp4

SESSION 9: A Helpful Interface And Starting Implied Odds Calculations

A powerful VBA application deserves an attractive and user-friendly interface since this where the user interacts with the file.  So, our first job in this video is to improve the interface.

This could be problematic since we have referenced cells in Excel VBA – so moving them around could create inaccuracies in the code.  This is where named ranges help.  I also show you how to use the find facility in the VBA editor to quickly understand if a cell is referenced in a macro.  The improved layout means I’m already feeling ‘more enthusiastic’ about working with the file …

But it’s not just about layout – where things are on the interface.  Formatting and data validation are important aspects of the user experience, too.  We dealt with formatting in the previous video and I add some additional points here – I recommend, at least, to change from Calibri (usually the default font type) to something else!  If you have a ‘user’ this shows them you’ve at least thought about the appearance of the interface.  Arial is my go-to font for Excel development – smart, readable and space-efficient, though I also accept Comic Sans for sentimental reasons, being a child of the 90s.

Cell-based data validation is essential in VBA applications for avoiding errors and developing robustness.  Data validation such as dropdown menus means inputs are predictable.  This helps with matters such as variable type selection (since variables often ‘receive’ data from the spreadsheet), and a host of other things.  Directive error messages tell the user what to do if an input is acceptable, smoothing the user experience.  Remember too, data validation does not just mean dropdown menus – a multitude of options are available including numerical controls such as ensuring a number is within a range.  Use them!  And ease the pressure VBA …

The rest of the video is concerned with calculating the implied odds that will populate the heatmap table.  With the main mechanisms (such as dynamic range definition) already in place, it’s more a case of re-organising existing structures than creating new ones. 

We’re getting there, and soon everything should come together.  We’ll relish that ‘punch-the-air’ moment when it comes!

Topics And Techniques

  • Helpful user interface layout in VBA applications

  • Create an ‘analysis last generated …’ message

  • Use the find tool in the VBA editor

  • Use the format dialogue box to optimize border formats

  • Apply data validation to user input cells with a custom error message

  • Insert a button to trigger a macro

  • Create a confirmation message box with Excel VBA

  • Calling other macros with Excel VBA

  • ‘Promoting’ a variable to module level

  • COLUMN formula

  • When and when not to use dropdown menus

  • Application.worksheetfunction in Excel VBA

  • Directive error messages

Heatmaps 9 Final.mp4
Heatmaps S2 V9 Start.xlsm
Heatmaps S2 V9 End.xlsm