Macro which creates US Map and colors in states based on data

glide2131

New Member
Joined
May 13, 2014
Messages
4
Hello, I am trying to make a US Map that is colored blue and then has certain states colored orange. (In my example all of the states with the number "1" in column "B" next to it should be orange.)

I was able to fumble my way through it using the recording tool but I keep getting errors when I use it on other computers.

2022-01-19 17_52_55-map test.xlsm - Excel.png


I have attached a workbook as an example. The lines that I am getting an error on are below:
error image.png


VBA Code:
 .SeriesColorMinGradientStop.StopColor.RGB = 49407 'color
        .SeriesColorMinGradientStop.StopColor.TintAndShade = 0
        .SeriesColorMinGradientStop.StopColor.Transparency = 0

Here is my code:

VBA Code:
Sub Mapmacro()

    Range("L13:M63").Select
    ActiveSheet.Shapes.AddChart2(494, xlRegionMap).Select

    ActiveChart.FullSeriesCollection(1).Select
    With ActiveChart.FullSeriesCollection(1)
        .SeriesColorMinGradientStop.StopColor.RGB = 49407 'color
        .SeriesColorMinGradientStop.StopColor.TintAndShade = 0
        .SeriesColorMinGradientStop.StopColor.Transparency = 0
    End With
    With ActiveChart.FullSeriesCollection(1)
        .SeriesColorMaxGradientStop.StopColor.RGB = 49407 'color
        .SeriesColorMaxGradientStop.StopColor.TintAndShade = 0
        .SeriesColorMaxGradientStop.StopColor.Transparency = 0
    End With
    ActiveChart.FullSeriesCollection(1).Points(40).Select
    
    ActiveChart.FullSeriesCollection(1).Points(33).Select
    ActiveChart.PlotArea.Select
    ActiveChart.FullSeriesCollection(1).Select
    
    ActiveChart.Legend.Select
    ActiveChart.SetElement (msoElementLegendNone)
    
  With ActiveChart.Parent 'This with statement tells the macro where to move the graph to on the page.
    .Top = Range("G4").Top
    .Left = Range("G4").Left

End With
   
    
End Sub

I would also like to widen the state lines if possible. And instead of using active sheet I need it to run sheet named "Sheet1".

Is anyone able to help me with this?

Thanks



Cross Posted:
https://www.excelforum.com/excel-programming-vba-macros/1368879-macro-which-creates-us-map-with-colored-in-states.html
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top