+ Reply to Thread
Results 1 to 2 of 2

colour interactive map based on data

Hybrid View

esbencito colour interactive map based... 10-09-2017, 02:00 AM
underscoreBadger Re: colour interactive map... 10-19-2017, 09:39 AM
  1. #1
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    colour interactive map based on data

    Hi all,

    I created a dashboard with a map of Japan that automatically visualises trends based on the data metric selected. Though, I want to keep all prefectures/provinces coloured 'black' with a white outline if there is NO data available. As an example, for the population data all prefectures have data available and should does be coloured accordingly, though, products aren't sold in all of them, thus, only the ones where data is available should be coloured. Currently it would colour them in the lightest colour (based on the legend defined)...

    This is the code I am using:

    Sub UpdateJapanColorScale()
    
    ' Update the RGB values and the colors of the legend after changing the color scale on worksheet [control]
    
    Dim i As Integer
    Dim rngJapan_MapValueToColor As Range
    Dim rngColorScales As Range
    Dim rngColorScaleSelection As Range
    Dim rngLegend As Range
    Dim myCell As Range
    
        ' Initialize
        
        Application.ScreenUpdating = False
        
        If Range("Selected_View").Value = 1 Then
        
            Set rngJapan_MapValueToColor = Range("Japan_MapValueToColor").Offset(0, 1).Resize(Range("Japan_MapValueToColor").Rows.Count, 1)
            Set rngColorScales = Range("Japan_myColorScales")
            Set rngColorScaleSelection = Range("Japan_myColorScaleSelection")
            Set rngLegend = Range("Japan_myLegend")
        
        ' Loop through the defined color scale and write the RGB values to the [control] sheet / format the legend cells on the map
        
        For i = 1 To rngJapan_MapValueToColor.Rows.Count
            rngJapan_MapValueToColor(i, 1) = rngColorScales(i, rngColorScaleSelection.Value).Interior.Color
            rngLegend(i, 1).Interior.Color = rngColorScales(i, rngColorScaleSelection.Value).Interior.Color
        Next i
        
        For Each myCell In Range("Japan_MapNameToShape").Columns(1).Cells
            CheckColor Range(myCell.Value), "Japan_MapNameToShape", "Japan_MapValueToColor"
        Next myCell
        
        Set rngJapan_MapValueToColor = Nothing
        Set rngColorScales = Nothing
        Set rngColorScaleSelection = Nothing
        Set rngLegend = Nothing
        Application.ScreenUpdating = True
           
        End If
        
        If Range("Selected_View").Value = 2 Then
        
            Set rngJapan_MapValueToColor = Range("Japan_MapValueToColor").Offset(0, 1).Resize(Range("Japan_MapValueToColor").Rows.Count, 1)
            Set rngColorScales = Range("JapanVAR_myColorScales")
            Set rngLegend = Range("Japan_myLegend")
        
        ' Loop through the defined color scale and write the RGB values to the [control] sheet / format the legend cells on the map
        
        For i = 1 To rngJapan_MapValueToColor.Rows.Count
            rngJapan_MapValueToColor(i, 1) = rngColorScales(i, 1).Interior.Color
            rngLegend(i, 1).Interior.Color = rngColorScales(i, 1).Interior.Color
        Next i
    
        ' Update the map to apply the new color to the choropleth map
        
        For Each myCell In Range("Japan_MapNameToShape").Columns(1).Cells
            CheckColor Range(myCell.Value), "Japan_MapNameToShape", "Japan_MapValueToColor"
        Next myCell
        
        ' Clean Up
        Set rngJapan_MapValueToColor = Nothing
        Set rngColorScales = Nothing
        Set rngLegend = Nothing
        Application.ScreenUpdating = True
    
    End If
    End Sub
    I would assume this could be fixed with a 'simple' If statement somewhere in between the lines of code?

    japan map forum.PNG

  2. #2
    Registered User
    Join Date
    10-12-2015
    Location
    Bristol, UK
    MS-Off Ver
    Office 365
    Posts
    39

    Re: colour interactive map based on data

    What happens if, in your dataset, you put an error value for prefectures where there are no sales? For example, type the formula
    Formula: copy to clipboard
    =NA()


    I use this trick in charts where I don't want a data point plotted (Excel likes to evaluate a blank as a zero).

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to change cell colour, if the colour is based on value from formula?
    By darah237 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-19-2016, 11:40 AM
  2. Replies: 6
    Last Post: 04-11-2016, 09:48 AM
  3. [SOLVED] Search cells based on student name, cell background colour and return a tally for colour
    By drof_06 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-26-2016, 04:31 AM
  4. Change colour of cells based on another cell's colour (Not value)
    By LTrain89 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-25-2013, 08:44 PM
  5. Colour change column chart based on cell colour
    By Alice21 in forum Excel General
    Replies: 11
    Last Post: 04-05-2011, 10:10 AM
  6. How to make row change colour based on text colour in row?
    By Joanna13 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-02-2010, 04:39 PM
  7. Change colour based on DDE data
    By neoen in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-10-2009, 06:58 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1