Excelmacros中的交互式地图

我在“9”以上的编码有麻烦。

Sub ColourStates() Dim intState As Integer Dim strStateName As String Dim intStateValue As Integer Dim intColourLookup As Integer Dim rngStates As Range Dim rngColours As Range Set rngStates = Range(ThisWorkbook.Names("STATES").RefersTo) Set rngColours = Range(ThisWorkbook.Names("STATE_COLOURS").RefersTo) With Worksheets("MainMap") For intState = 1 To rngStates.Rows.Count strStateName = rngStates.Cells(intState, 1).Text intStateValue = rngStates.Cells(intState, 2).Value ' single colour intColourLookup = Application.WorksheetFunction.Match(intStateValue, Range("STATE_COLOURS"), True) With .Shapes(strStateName) .Fill.Solid .Fill.ForeColor.RGB = rngColours.Cells(intColourLookup, 1).Offset(0, 1).Interior.Color End With Next End With 

结束小组

这里是文件本身的链接: https : //dl.dropboxusercontent.com/u/41007907/MapOfStates.xls

它适用于低于9的值,但我需要它的工作,直到20。

您的数组STATE_COLORS仅包含0到9间隔内的值。 这里是你需要进行的步骤:1)打开excel文件2)转到公式标签3)点击名称pipe理器4)selectSTATE_COLORS数组5)增加值到20

如果您有任何其他问题,请回到我身边。

Interesting Posts