2013-04-14 74 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