Faster Choropleth Maps with Microsoft Excel

An improved version of a Microsoft Excel Choropleth Map with a better performance for detailed maps

Choropleth Map US Unemployment by CountyVery soon after starting this blog in 2009 I published a post with a set of Microsoft Excel Choropleth Map templates.  This post is still one of the most popular articles and downloads here.

A lot of related posts followed and I am feeling very honored that my blogging colleague and France’s data visualization guru Bernard Lebelle of Impact Visuel used 2 of my maps published here on Clearly and Simply in his great new book “Convaincre avec des graphiques efficaces”. Bernard was kind enough to point his readers to my blog in the book. This is much appreciated. However, he should have heaped the praise on Tushar Mehta, who invented this technique. I only “stole” Tushar’s idea.

Tushar’s approach works great and I know from comments and emails that a lot of my readers have used it with great success.

There is only one minor drawback with Tushar’s approach: the performance decreases considerably when using it on a map with a lot of shapes, like the US by Counties.

Today’s post tries to heal this. It discusses how to considerably improve the performance of a detailed map. The article describes the original approach, the optimization potential, the improved implementation and – as always – provides the Excel workbook for free download.

The Original Approach

I know I mentioned this on several occasions before (and in the introduction, too), but I want to reemphasize it once more: the approach how to create Choropleth Maps in Excel wasn’t my idea. The whole concept and the VBA code is the brainchild of Tushar Mehta, long time Microsoft Excel MVP, who published this with an example workbook (Conditional Color of Shapes) a long time before I wrote my first article on Choropleth Maps with Excel here.

Here are the cornerstones of Tushar’s technique:

On the worksheet(s):

  1. A map with one Microsoft Office shape for each region (e.g. US state)
  2. Each shape has a name (e.g. S_CA for the shape of California)
  3. One named range for each cell containing the data to be visualized (e.g. D_CA for California)
  4. A lookup table assigning the named shapes to the named ranges (the data). This range with this lookup table is called “MapNameToShape”
  5. Another lookup table assigning RGB values (the colors) to a defined number of bins (thresholds to define which value will be visualized by which color). This lookup table has the range name “MapValueToColor”

The VBA consists of 2 main routines:

The sub UpdateMap loops through all cells of the lookup table MapNameToShape and calls the second sub “CheckColor” for each shape / data point.

The sub CheckColor looks up the shape name of the currently processed region (passed through by the calling sub UpdateMap) and detects the RGB color for the current value using the worksheet function VLOOKUP on the table MapValueToColor. Finally it sets the fill color of the current shape to this RGB color.

Named ranges and lookup tables in the worksheet, 30 (!) lines of VBA code and you are good to go. As I said in my first post on Choropleth Maps, Tushar’s idea is as brilliant as it is simple and I can’t thank him enough for sharing this technique.

The Challenge

Tushar’s technique is really straightforward and pretty easy to implement. Even more important it works well and proved to be very stable with all maps I ever used it for.

There is only one little downside: the performance of the code considerably decreases if you are using maps with a lot of regions. The US map by counties (more than 3,000 shapes), for  instance, takes more than 21 seconds on my computer to update. This may count for little if you need to create a map as a one-off solution e.g. for inserting it into your PowerPoint slide deck. However, if you want to use a big map with a lot of shapes on an interactive dashboard and the map needs to be updated on user request, the performance is a real issue. 20 seconds to update a dashboard is everything else than a perfect user experience.

Good news: Tushar left some room for improvement. The VBA code is not as simple anymore, but the performance gain is worth the effort.

The Background

Why is the code becoming so slow with a large number of shapes?

Root cause of most performance issues of Excel VBA workbooks is the fact that Microsoft Excel and VBA are 2 separate applications. Going through the barrier between Excel and VBA is really costly in terms of performance. 

With “going through the barrier” I mean reading data from the workbook by VBA, writing results from VBA to the workbook or using Microsoft Excel worksheet functions (Application.WorksheetFunction) in the VBA code. It goes without saying that it is inevitable to go through this barrier when using VBA in Excel workbooks. However, if you want to maximize the performance of your Excel VBA model, you should try to minimize the number of times your code is going through the barrier.

Exactly this is the starting point for today’s post. The original approach

  1. reads one cell to get the name of the named range of the data point
  2. reads the value of the named range
  3. detects the name of the shape
  4. checks if the value belongs to the first bin
  5. if the value belongs to the first bin, it gets the first RGB color
  6. otherwise it uses Excel’s VLOOKUP function to get the RGB value from the table “MapValueToColor”
  7. finally it formats the shape with the fill color found in step 5 or 6

Each of those steps goes through the barrier at least one time (the VLOOKUP even more often).

This is no problem as long as you are using a US map by state (i.e. 50 shapes) or the World Map (i.e. ~ 190 countries), but it definitely becomes an issue with several thousand shapes.

The Improved Version

What’s different in the improved version?

On the worksheet(s):

  1. The named ranges for the data points of each shape / region (e.g. D_CA) have been replaced by one named range (“myValues”) covering all data values of all regions. As a consequence, the named range “MapNameToShape” does not exist anymore.
  2. An additional column on the worksheet [data] contains the index number of each shape. This index is used in the VBA to assign a value to a shape. The VBA also contains a sub to create the values of this column automatically after inserting another map (see also section “The Bonus Features” below)

There are quite a few other things I changed on the worksheets, but all of those are for implementing the additional features which are not essentially for the pure Choropleth Map functionality.

The VBA Code:

I will not go into each detail of the VBA code here. I tried to comment the code the best I could, so if you are interested in the details, download the workbook and have a look for yourself. If you have any questions, please leave me a comment.

Here are just the major changes of the new approach in a nutshell:

  1. The code is not reading the data, the bins and the shapes step by step, but rather pushes them into VBA arrays in one go
  2. The code does not use the worksheet function VLOOKUP anymore
  3. The values / shapes are assigned to the bins, i.e. the code detects which shape / value belongs to which bin and which color it will get
  4. A shape range object is used to format the shapes not one by one, but rather format all shapes belonging to one bin in one go

This new approach minimizes the number of times the VBA has to go through the barrier to the Excel workbook and thereby considerably improves the performance of the map.

Considerably? Really?

Yes.

Updating a map now takes between 2 to 3 seconds on my computer (a bit more with the progress information in the status bar, see below) and compared to the 21 seconds we had before I think it is fair to call this a considerable improvement. Agreed, still not perfect, but way better than before.

The Bonus Features

In order to provide a nice workbook for your testing, I added a few new features:

  1. Real Data

    The Choropleth Map visualizes the US unemployment rates from 2003 to June 2012 by county (source: Bureau of Labour Statistics).

  2. Different Color Scales

    The workbook includes 23 different color scales I mostly took from the great online tool Color Brewer (color advice for cartography). You can change the colors of the map by simply selecting a new scale from a drop down.

  3. Legend

    A legend on the map shows the colors and the size of the bins they represent next to the map. It goes without saying that this legend is automatically updated after you selected a new color scale.

  4. Optional Status Bar Progress Information

    The performance of updating the map is somehow borderline in terms of user experience. Much faster than before, but still 2 or 3 seconds to update the map. You may want to keep your user informed about what is happening by displaying progress information in Excel’s status bar. However, updating the status bar takes additional time, so you can chose on worksheet control whether you want to do this or not.

  5. Recreate the Shape Index

    Last but not least the code also provides a sub to automatically recreate the index of the shapes (see also the section “The Improved Version” above). Not a feature for everyday use, but helpful if you want to use the workbook as a template, insert your own shapes and create your own Choropleth Map.

That’s it.

The Download Link

Here is the Microsoft Excel workbook including the faster version of the Choropleth Map (United States by County) for free download:

Download Choropleth Map US Counties Faster (Microsoft Excel 2007/2010 workbook, 2,505.7K)

What’s next?

I am having one or two more ideas on VBA performance and I hope to publish them soon. Also, some interesting Tableau posts are still waiting in my pipeline.

More things to come soon, so please stay tuned.

Comments

76 responses to “Faster Choropleth Maps with Microsoft Excel”

  1. Seth Avatar
    Seth

    Excellent! I’ve used this technique for occasional one-offs but have never bothered to productionize anything because the performance was so clunky for county-level. Thanks!

  2. Jon Avatar

    I did a heat map for stadiums/arenas using Excel. Because of all the shapes (even after changing the workbook to xlsb type) it had problems just opening. Eventually I just used excel to Export the data (parse) into CSS/HTML format. After doing that it was extremely fast. I had to do a custom CSS/HTML writing but it was worth it. Excel is nice because you don’t need to create all your own controls for settings, etc.
    Great work on your and Tushar’s map!

  3. Fulvio Avatar
    Fulvio

    I really envy your ideas and how clean you can implement and organize your workbooks.
    Its just simply amazing.
    Your blog is by far one of the most interesting in my list.
    Thank you so much for all your posts.

  4. jan Avatar
    jan

    Hi,
    you have my deep admiration, great work indeed.
    Could you please give me a hint on how to import maps of other countires – perhaps there is a collection of maps ready to import and work with..
    Many thanks,
    Greetings from the Czech Republic

  5. Robert Avatar

    Jan,
    thanks for your comment. Have a look at this article:

    Build your own Choropleth Maps with Excel

  6. Sean Avatar
    Sean

    Wow. I’ve always used ESRI products for mapping in my last couple jobs. I just changed careers and we don’t have any licenses here, (and won’t), but I still love visualizing geo data whenever I can. This Excel template will do 90% of what I used to do in ESRI. This is so cool. Many thanks for sharing.

  7. Robert Avatar

    Sean,
    thanks for your comment and your very kind words.
    Out of sheer curiosity: what are the 10% of functionality you are missing? I would assume zooming in and out is one of them, right? Interactive zooming would be quite a challenge in Excel (if not impossible), but maybe you have some further ideas which could be realized in Excel?

  8. Amit Avatar

    Hi Robert,
    I am very impressed with the detail work you have done.
    Looks like there is no need to buy the mapping tools/softwares for Excel 2010 :)..very well done.
    On another note, I am trying to figure out how to open this in plain Excel 2010 application. As it is all in XML, looks like I am missing a whole lot…
    Thanks,
    Amit

  9. Robert Avatar

    Amit,
    thanks for your comment. Microsoft Excel 2007/2010 files are in fact zipped folders containing XML and other files. Depending on the settings of your system, it may well be that Windows tries to open the file as a zipped folder with Windows Explorer and then you only see the XML files. Simply right click on the link, select Save As and save the file to your computer. You should then be able to open the file with Microsoft Excel by simply double clicking.

  10. Amit Avatar

    Thank you, Robert. It worked like a charm.
    Appreciate your prompt response :):)
    Thanks again.

  11. John Avatar
    John

    Not sure what I’m doing wrong, tried renaming a few of the shapes and adding some with the original names from the ones changed but the new don’t change colour and the old ones still do?

  12. Robert Avatar

    John,
    after inserting additional shapes or replacing shapes you have to
    1. make sure all other objects on the worksheet (like the drop downs) are the last objects on the sheet
    2. recreate the shape index (see point 5. of the section “The Bonus Features”) and the command button on the control worksheet.
    Please give it a try and let me know if it is still not working for you.

  13. john Avatar
    john

    Hi Robert,
    thanks for the reply been tied up recen tly but back to re visit this now, I’ve run the recreate shape index macro but it doesnt add the new shape.
    But I’m not quite sure what you mean by point 1. make sure all other objects are the last objects?
    regards
    John

  14. Robert Avatar

    John,
    did you add the shape names to column I on the sheet data (the named range “myShapeNames”) and does “myShapeNames” refer to the entire list of all shape names?
    With regards to point 1 in my previous comment: if you have other objects on the sheet than the shapes of the map (the 2 drop downs in my example), you have to make sure they are the last objects on the sheet. Go to the Selection Pane (Home Tab | Find&Select | Selection Pane or ALT-F10). The additional objects (the drop downs) have to be at the top of the list shown in the Selection Pane. If not, you can rearrange the shapes with the 2 little arrows at the bottom of the Selection Pane.
    If it is still not working for you, you may want to send me your map by email and I will have a look.

  15. Michal Avatar
    Michal

    Robert,
    This is just amazing job that you are doing here, this tool is an absolute beauty!
    One question though relating to John’s troubles which I’ve also encountered. Is there a more efficient way of changing the order of the objects in the ALT-F10 pane? I have a couple of hundreds of objects and clicking the arrow through all of them seems a bit tough way of doing it (not that I know any better one!)
    best,
    Michal

  16. Michal Avatar
    Michal

    Forget it, probelm solved – I’ve just selected all of them and moved all at once 🙂

  17. Dave Avatar
    Dave

    Robert,
    I tried downloading the file so that I could look at it, but everything is in XML format, not xls. It’s like the file has been broken down into it’s component parts and no longer loads in Excel.
    Am I doing something wrong?
    Dave

  18. Robert Avatar

    Dave,
    Excel 2007/2010/2013 files actually are nothing else than zipped folders containing XML and other files. I suppose your browser tries to open these files directly with Windows Explorer. Just right click on the link, select Save As, save the file to your hard drive, double click on it and the workbook should open in Excel.

  19. John Petersen Avatar
    John Petersen

    Can anyone tell me how to install this “faster” pack?

  20. Robert Avatar

    John,
    you do not have to install anything. Right click on the download link, select Save As, save the workbook to your computer, open it with Excel, enable the macros and you are good to go.

  21. Stephan Avatar
    Stephan

    Hello Robert,
    very impressing work!
    I miss only two, but for me important things.
    1.) Is it possible to show the name of the Shape plus the selected value under the name?
    (e.g. show “California” “10%”; “Florida” “15%”)
    2.) how can I group shapes to regions (e.g. “WestCoast”)?
    Thank you in advance!
    Stephan

  22. Robert Avatar

    Stephan,
    I think the follow up article should answer both of your questions:

    Fast Choropleth Map with Enhanced Features

  23. Peter Avatar
    Peter

    Wow great work – I wonder if somebody already built a world map with the new version ??

  24. Robert Avatar

    Peter,
    you do not need the faster version for a World Map with only 200 countries. Tushar’s original approach is fast enough to color those very quickly.
    Having said that, if you still want to transfer the World Map to the workbook posted above, deleting the existing shapes and data, inserting the World Map Shapes, deleting the not required rows on the data sheet and running the Recreate Shape Index sub is pretty much all you have to do.

  25. Andy Avatar
    Andy

    Robert,
    This is really great and very helpful! I have been able to recreate the shape with different maps as per instructions. However, I always have the same problem when updating the map. It seems that the value in column O is not following the right sequence, in my case Shape no 1’s value would be in O8 when it should be in O5. I have tried it with different maps and still have the same issue.
    could you please help me with this? Thanks a lot!
    Andy

  26. Robert Avatar

    Andy,
    I would assume, you have other objects in your worksheet than the shapes representing the regions of the map, like the drop down combo boxes in my example, right?
    If so, you have to make sure those are the last shapes on the worksheet. Go to the Selection Pane (ALT-F10) and make sure all shapes not belonging to the map (i.e. not supposed to be colored by the algorithm) are at the top of the Selection Pane, which shows the shapes in reverse order. You can use the arrows or drag and drop them in the Selection Pane. After you did, simply rerun the Recreate Shape Index sub (button on the control worksheet) and it should be working.

  27. Andy Avatar
    Andy

    Hi Robert,
    Thank you so much!! It works like a charm!
    Happy days 🙂
    Andy

  28. Steven Avatar
    Steven

    Fantastic worksheet, this is really what I’m looking for so I tried to implement your way of working in an existing worksheet using the same cell naming, make sure the shapes are ordered correctly, adjusted the index number of the sheet showing the map in your VBA code but when I try to run then the RecreateShapeIndex macro I always get stuck on this programming code: “varShapeIndex(lngCount) = Sheets(C_SHEET_NUMBER).Shapes(varShapeNames(lngCount, 1)).ZOrderPosition”
    Do you have an idea what can cause the issue?
    Thanks!

  29. Robert Avatar

    Steven,
    thanks. I am glad you find this useful.
    I assume the run time error message is “The item with the specified name wasn’t found”, correct?
    If so there is probably at least one mismatch between the definition of the names in “myShapeNames” and the names of the shapes on the map. Maybe a trailing space, a typo, a missing character, etc.
    Let the sub run again, click on Debug and in the VBE hover over the part “…varShapeNames(lngCount…” of the yellow line with the mouse and you will see the name of the problematic shape in a tooltip.
    Then go to the worksheet(s) and make sure the shape name matches with the definition of the name on the data worksheet.
    You may have to repeat this several times, if there is more than one mismatch.
    If you can’t find the issue, please send me your workbook and I will have a look.

  30. Steven Avatar
    Steven

    Thx for the great tip. I found the issue.

  31. Srijith Ramachandran Avatar
    Srijith Ramachandran

    Dear Robert,
    You are just great…i was just wondering what does this code of your do “Sheets(C_SHEET_NUMBER)”? is this the sheet in the workbook. and how do i change the map by a world map..
    Your advise will be higly appreciated..

  32. Robert Avatar

    Srijith,
    C_SHEET_NUMBER is a public constant (set to 1) defined at the top of the module
    modChoroplethMap. The statements using Sheets(C_SHEET_NUMBER) thereby always refer to the first sheet in the workbook (the map). If you move the sheet with the map to another position in the workbook (e.g. the data sheet first and then the map), you have to change this constant to 2. The problem here is the following: you can address a worksheet in VBA referring either to the index number of the sheet (as I do) or to the name of the sheet. If you refer to the index number, the user shouldn’t move the sheet to another position. If you refer to the name of the sheet, the user shouldn’t rename the sheet. So it is the choice between a rock and a hard stone. The problem remains: changes in the workbook (sheet position or sheet name) may require changes in the VBA.
    Regarding the World Map: actually you do not really need the faster version for a World Map. Tushar’s original approach is fast enough for only 200+ countries. Have a look at my reply to Peter on September 4, 2014 above.

  33. Srijith Ramachandran Avatar
    Srijith Ramachandran

    Dear Robert,
    many thanks for the explanation..have a nice weekend..

  34. Rusty Avatar
    Rusty

    Hi Robert,
    I am trying to use different value ranges for when the user selects from the drop-down in cells L2:M2 on the map worksheet. I.e. depending on the filter selected from the drop-down, the map would use a different threshold range. I want to use 3 different threshold ranges in my current project, and I would then display 3 legends.
    I already figured out how to change the value displayed when the user hovers over a particular county on the map (the default was %, and I changed to whole numbers). But I assume this would also need to be updated based on the filter selected from the drop-down.
    Any help here would be greatly appreciated! I absolutely love this map.

  35. Robert Avatar

    Rusty,
    I think you can do this without changing the VBA code:
    To use different threshold ranges depending on the selected measure, I would recommend to define the ranges somewhere on the worksheet control and then use INDEX formulas to get the currently selected threshold range in the first column of the defined name myMapValueToColor based on the currently selected measure (i.e. the value in cell C15).
    If the measures have different number formats, you have to adjust the formulas creating the legend texts (D19:D28 on the control worksheet) based on the currently selected measure (e.g. by using a CHOOSE formula).
    Finally, if the different ranges have a different numbers of bins, you would have to change the named range myMapValueToColor. It now refers to a fixed cell range (B19:C28). If the measures have different numbers of bins, you would replace this range reference by an OFFSET formula based on the number of bins of the currently selected measure.
    I hope this will be helpful.

  36. Rusty Avatar
    Rusty

    Robert,
    Thanks so much for the quick response. I actually used a HLOOKUP to select the threshold range from a newly created threshold ranges table (per your suggestion). I believe this gave me the same result as an INDEX formula in cells B19:B28 (on control tab) would have. It is working beautifully now.
    Thanks again. And where are you teaching classes?
    -Rusty

  37. Robert Avatar

    Rusty,
    good to hear you got it working.
    HLOOKUP, VLOOKUP, OFFSET, INDEX. There is always more than one way to skin the cat. I am preferring INDEX to fetch values from cell ranges, because it usually is the fastest option, but this doesn’t matter in your case.

    “And where are you teaching classes?”

    Only here. I am doing onsite trainings in Germany from time to time, but I guess this won’t help you. No videos or even a comprehensive online course. I am sorry.
    If you are looking for a good online Excel academy, I am recommending Chandoo’s Excel School:

    Chandoo’s Excel School

    And, for the more advanced user, Daniel Ferry’s Excel Hero Academy:

    Excel Hero Academy

    Both are well worth the money. If you are interested, please have a look. Please be advised that I am not an affiliate and I do not get money for these recommendations.

  38. Houssain Kettani Avatar

    Robert,
    Could you please update and share Choropleth Map World Color Scale Excel file with Kosovo and South Sudan included?

  39. Robert Avatar

    Houssain,
    I am sorry, no, I can’t. Clearly and Simply is supposed to provide tips, tricks and techniques for data analysis and data visualization with Excel and Tableau. Templates and example workbooks are just provided as showcases. They are “as-is” at the time the article was published. I do not have the time to keep all example workbooks up to date and I never claimed I would.
    If you need an updated version of the World Map, I suggest you check out the articles explaining how to create your own Choropleth Map in Excel and make the update on our own.

  40. Bobby Avatar
    Bobby

    Hello,
    Let’s say that I have the data being imported every hour that feeds the map. The problem I have is that I have to change the drop down selection and make the selection again for the data to show. Is there a way to change the code to run on a timer or something?

  41. Robert Avatar

    Bobby,
    you could e.g. call the Choropleth Map sub in the Worksheet_Change event sub of the data worksheet. Every time the worksheet changes (if new data comes in), the procedure is fired and the map gets updated.

  42. Bobby Avatar
    Bobby

    Robert,
    Thank you for the reply. I am not that good at coding yet, but am learning. Could I add something like this into my current code? If so, how would you suggest I do it:
    alertTime = Now + TimeValue(“00:05:00”)
    If my current code looks like this:
    Option Explicit
    Function udf_RGB(myR As Byte, myG As Byte, myB As Byte) As Long
    udf_RGB = RGB(myR, myG, myB)
    End Function
    Sub CheckColor(myCell As Range, myNameToShape As String, myValueToColor As String)
    Dim myShape As Shape
    Dim myTargetCell As Range
    Dim myColorCode As Long
    On Error GoTo Catch
    Set myTargetCell = Range(myNameToShape).Columns(1).Find(myCell.Name.Name, LookAt:=xlWhole)
    Set myShape = Sheets(1).Shapes(myTargetCell.Offset(0, 1))
    GoTo Finally
    Catch:
    Exit Sub
    Finally:
    On Error GoTo 0
    If myCell.Value < Range(myValueToColor).Cells(2, 1).Value Then myColorCode = Range(myValueToColor).Cells(1, 2).Value Else myColorCode = Application.WorksheetFunction.VLookup(myCell.Value, Range(myValueToColor), 2, True) End If myShape.Fill.ForeColor.RGB = myColorCode End Sub Sub UpdateMap() Dim myCell As Range Application.ScreenUpdating = False For Each myCell In Range("MapNameToShape").Columns(1).Cells CheckColor Range(myCell.Value), "MapNameToShape", "MapValueToColor" Next myCell Application.ScreenUpdating = True End Sub

  43. Robert Avatar

    Bobby,
    first of all, you are obviously using the simpler code published in previous posts. I do not know how many regions your map has, but I would strongly recommend the faster algorithm provided in the article above.
    As for your question: if you place a timer inside your code, the code has to run all the time. That’s why I recommended to use an event driven procedure.
    The Worksheet_Change sub of a worksheet is fired every time something changes on this sheet and this seems ideal for your purposes.
    Simply put this procedure into the worksheet object in VBA (Microsoft Excel Objects | Tabelle02 (data)):
    Private Sub Worksheet_Change(ByVal Target As Range)
    UpdateMap
    End Sub
    I do not know in which way you are updating your data, but this doesn’t really matter. As soon as something changes on the worksheet data, the sub will be executed and the map will be updated.

  44. Bobby Avatar
    Bobby

    Robert, your skill is legendary. That worked perfectly for me.
    You are correct, I am using the much simpler code. I only have 40 areas or so. I am going to upgrade soon to the algorithm provided here soon. I appreciate the help.

  45. Isabella Avatar
    Isabella

    Hi Robert – the link doesn’t contain an excel file. Am I doing something wrong. I d/l a zipped file but it doesn’t contain an excel file. Please help.
    The Download Link
    Here is the Microsoft Excel workbook including the faster version of the Choropleth Map (United States by County) for free download:
    Download Choropleth Map US Counties Faster (Microsoft Excel 2007/2010 workbook, 2,505.7K)

  46. Robert Avatar

    Isabella,
    since version 2007, Microsoft Excel files are actually zipped folders including XML and other files. If your Internet browser opens Windows Explorer when clicking on the download link, right click on the link instead and select “Save Target As” to download. If you are using Microsoft’s Internet Explorer, the IE will change the file extension from .xlsm to .zip during download. Simply change the file extension back to .xlsm and you can open the workbook with Excel by double clicking on the file.

  47. Bella Avatar
    Bella

    Thanks Robert. I opened it soon after I posted. I was about to take the post off but you had replied.

  48. Robert Avatar
    Robert

    Hi, this mapping tool is fantastic and a real help, thank you. I wanted the global map, but with the tooltips and filters so I’ve copied across the global map and recreated the index. All works well, except Ethiopia and Afghanistan always display a colour, even when there is no data for these countries. Can you think why this may be? Everything else seems to work fine. I can manually recolour Afghanistan to grey so it is always ignored, but Ethiopia seems to always get coloured again, even though there’s no data for this market. (I’m not sure if it’s relevant but I’ve added extra colours in the scale and changed the associated ranges and also added extra columns of data but also included these in the drop down). Many thanks

  49. Robert Avatar

    Robert,
    you probably have other objects on your sheet than the map shapes, like the combo boxes in my original workbook.
    If so, you have to make sure those are the last shapes on the worksheet. Go to the Selection Pane (ALT-F10) and make sure all shapes not belonging to the map (i.e. not supposed to be colored by the algorithm) are at the top of the Selection Pane, which shows the shapes in reverse order. You can use the arrows or drag and drop them in the Selection Pane. After you did, simply rerun the Recreate Shape Index sub (button on the control worksheet) and it should be working.

  50. Robert Avatar
    Robert

    Hi Robert,
    Many thanks for the quick response. I’m afraid I had already ensured all the map objects are at the bottom of the list and I’ve read all comments in this thread and the others on chloropleth maps on this website to try and find a solution. I don’t suppose you have a version of the “faster chloropleth map” with tooltips and filters but with the global map and not United States that you could send me? It would be hugely appreciated if you do but I’m not asking you to create this if not. Cheers

  51. Robert Avatar

    Robert,
    if the sort order of the shapes isn’t the problem, you may want to send me your workbook by email (email-address at the top of the blog) and I will have a look.
    As per your second question: unfortunately, no, I do not have a world map version with filters and tooltips, but it shouldn’t be too difficult to replace the US map by a world map in the template I provided. Not much more than an hour or two, I think.

  52. Simon Avatar
    Simon

    I have to say – one more time I realize how little I know about excel, macros and other fancy stuff. I consider myself pretty good with excel, but I suppose I am still a total beginner. The template is great and was exactly what I was looking for! Thank you very much for sharing this!

  53. Camille Avatar
    Camille

    How can I add values to the shapes of my map? If I want to show that unemployment rate for Florida was 4%, how can I make my map show the name Florida and the 4% value?

  54. Robert Avatar

    Camille,
    the maps are a collection of freeform shapes and you cannot assign a text to freeform shapes.
    Hence, if you want to display additional information, you have to add textboxes, position them where you want them to have and finally write some additional VBA code to update the text in the textboxes. The latter is not necessary for the names of the regions, but it is necessary for the textbox displaying the value (to be updated after the data changed or another measure is selected).
    Having said that, I would not recommend this, because it will clutter the display and does not add much value. I would rather use tooltips on the map showing the region names and values when hovering over a region (see the follow-up article to this post) or add a sorted bar chart next to the map visualizing the regions and their values.

  55. Jeff Avatar
    Jeff

    Thank you! I’ve been pulling my hair out trying to figure out what I was missing!

  56. Erika Avatar
    Erika

    Hola estimado Robert esta muy interesante tus mapas eres un capo necesito tu ayuda ya solo tengo algunos conocimientos en excel no soy tan buena que digamos pero en algo me defiendo he hecho el cambio de las formas pero solo estoy trabajando con 4 colores; 0= si es sin riesgo y la forma debe de aparecer en blanco y los que tiene valor con formula bajo riesgo, mediano riesgo y alto riesgo pero no me pinta las formas como yo quiero deacuerdo a los valores de la hoja de control como esta configurada dependiendo de los rangos que estan no se si algo estoy haciendo mal me puede ayudar

  57. Erika Avatar
    Erika

    Si gustas te envio la hoja de trabajo estimado Rober para ver donde estoy fallando y me puedas dar tus sugerencias.

  58. Robert Avatar

    Erika,
    I am sorry, I don’t speak Spanish. I used Google Translator, but I am not sure I fully understand your question. What I think I understood is that you want to use only four colors based on formulas. This shouldn’t be a problem. Maybe you can send me your workbook by email (E-Mail link at the top of the blog) with a description in English what issue you are facing and I will have a look as soon as possible.

  59. Erika Avatar
    Erika

    Dear friend to rober in the top where it says email not to work I do not know which mail to direct my book

  60. Erika Avatar
    Erika

    I do not know if you can send the file to send the email because the link at the top does not work

  61. Robert Avatar

    Erika,
    the link at the top still works fine for me, but if it doesn’t work for you, please send your mail to
    clearlyandsimply [at] online [dot] de

  62. Erika Avatar
    Erika

    Dear Rober the truth that I already registered and did what I asked but I can not send my file I do not know what would happen that not only that link to send my file does not work and is the only one that works not if there will be another mechanism or email to which I can direct my workbook so you can visualize it

  63. Erika Avatar
    Erika

    ready friend rober the problem has been the computer I was using right now I send you the file with the details thanks

  64. Ismail Avatar
    Ismail

    Hi,
    How to get MSA level Choropleth Maps for USA, do you have any examples

  65. Robert Avatar

    Ismail,
    I do not have a template of a USA MSA Choropleth Map in Excel, but you could try to find the ESRI Shape Files online and create your own Excel map. Have a look at this article:

    Create Excel Choropleth Maps from Shape Files

  66. Ismail Avatar
    Ismail

    Thanks Robert for your reply, sure I’ll check this

  67. Ismail Avatar
    Ismail

    Hi Rboert,
    Would these “ClearlyandSimply” Excel templates are free licensed, could we use these templates with other data for our purposes

  68. Robert Avatar

    Ismail,
    I am publishing my content under a Creative Commons License. Please refer to the link in the section “License” on the left sidebar of the blog.

  69. Ismail Avatar
    Ismail

    Thanks Robert,
    So I could understand, the use of your sample Coropleth map templates only offline and for non commercial use

  70. Robert Avatar

    Ismail,
    I am not sure what you mean by “only offline”, but “non-commercial” does not mean that you are not allowed to use the code and template in a corporate environment. You can use the template and code in the models you are creating for work, but you are not allowed to sell the template as it is.

  71. Ismail Avatar
    Ismail

    Thanks Robert,
    I understood now.

  72. Noel Avatar
    Noel

    Hello Robert,
    Thank you for this excellent tutorial. Would you happen to have an updated version of the U.S. map that includes the tool tip on hover? Also, is it possible to use number of events by county (i.e. homes bought/sold) by county, rather than a percentage? I have the raw data but can’t seem to figure out how to change the plotting from percentage to the sum of homes bought/sold by county in a single year.
    Kind regards,
    Noel

  73. Robert Avatar

    Noel,
    regarding tooltips: please refer to the follow-up article to this post.
    If you want to use integer or float numbers instead of percentages, you have to adjust the bins (thresholds) defined in cell range B19:B28 on the [Control] worksheet. You would also have to change the formulas in the corresponding column D to display the legend correctly.

  74. Matt Avatar
    Matt

    Hi Robert- not sure if you still reply to this, but hoping you do. I imported your file into my own worksheet so we can look at various data points across counties. On the ‘data’ tab, I’ve gotten rid of on column, M, and now have columns D-L linked to another data tab in my workbook. The selection column is still using an index to pull in the correct data I want to show on the map. My problem is that the map does not change based on my selection. It almost appears as if it’s still linked to the file I downloaded, despite me moving everything over to my own workbook. Any suggestions?

  75. Robert Avatar

    Matt,
    if you transfer the map, the sheets and the code to another workbook, there are quite a few things to consider, like making sure you copied the entire VBA code to your workbook or making sure the named ranges are available and correct in your workbook.
    My wild guess would be that you do not have defined the named ranges in your workbook (like myShapeNames, my Values, etc.). The code is referring to those named ranges and if you haven’t defined them properly in your workbook, the map will not update.
    So, please check the named ranges first. If this doesn’t solve the issue, you can send me your workbook by email (email link see the top of the site) and I will have a look.

  76. Matt Avatar
    Matt

    Robert- I really appreciate your quick reply! I had made sure to transfer the three VBA modules over, have all named ranges in mine, and also that the sheet was the first in the workbook and I still have there error. I do really appreciate the offer to take a look at the workbook but unfortunately due to some non-public information in there I will not be able to share. I don’t want to put you through any trouble so unless there’s some other simple thing you think I may have missed, I’ll most likely just copy and paste my data from my workbook into your workbook each time I need to update the map.

Leave a Reply

Your email address will not be published. Required fields are marked *