【发布时间】:2016-02-04 16:37:01
【问题描述】:
我有一个 VBA 代码,其中选择(固定)从 0 到 13 的数字,从这里将提供具有相应颜色的地图。但是...我想将其更改为每种颜色的范围。例如,我不希望将“1”与深蓝色耦合,将“2”与浅蓝色耦合等,但我想要一个范围。比如:0 - 50 --> 深蓝色,50 - 100 --> 浅蓝色等数字。
在下面的 VBA 代码中,您可以看到高于 13 (intStateValue) 的数字是由另一个协议提供的。但是代码中没有范围(For intState = 1 To rngStates.Rows.Count)。如何创建如上所述的范围(0 - 50、50 - 100、100 - 150 等)?
希望任何人都可以帮助我解决这个问题!提前致谢!!
Option Explicit
Sub Kleurgemeenten()
'
' Using the values from named range POSTCODEGEBIEDEN
' And the colours from named range KLEUREN
' re colour the map on sheet MainMap
'
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("GEMEENTE").RefersTo)
Set rngColours = Range(ThisWorkbook.Names("KLEUREN").RefersTo)
With Worksheets("MainMap")
For intState = 1 To rngStates.Rows.Count
strStateName = rngStates.Cells(intState, 1).Text
intStateValue = rngStates.Cells(intState, 2).Value
If intStateValue > 13 Then
' stripped
With .Shapes(strStateName)
intColourLookup = Application.WorksheetFunction.Match(CInt(Left(CStr(intStateValue), 1)), Range("KLEUREN"), True)
.Fill.Patterned msoPatternWideUpwardDiagonal
.Fill.ForeColor.RGB = rngColours.Cells(intColourLookup, 1).Offset(0, 1).Interior.Color
intColourLookup = Application.WorksheetFunction.Match(CInt(Right(CStr(intStateValue), 1)), Range("KLEUREN"), True)
.Fill.BackColor.RGB = rngColours.Cells(intColourLookup, 1).Offset(0, 1).Interior.Color
End With
Else
' single colour
intColourLookup = Application.WorksheetFunction.Match(intStateValue, Range("KLEUREN"), True)
With .Shapes(strStateName)
.Fill.Solid
.Fill.ForeColor.RGB = rngColours.Cells(intColourLookup, 1).Offset(0, 1).Interior.Color
End With
End If
Next
End With
结束子
【问题讨论】: