2013-04-14 67 views
1

我有上述“9”的编码的烦恼。交互式地图在Excel宏

   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

回答

1

你的阵列STATE_COLORS仅包含0到9间隔内的值。下面是你需要进行的步骤: 1)打开Excel文件 2)到公式标签 3)单击名称管理器 4)选择STATE_COLORS阵列 5)增加值20

获取回到我身边,如果你有任何其他问题。

+0

感谢那些工作的伟大 – Buras