0
您能否帮我获取vba代码以突出显示此列的最小值和最大值?如何使用此流程图创建宏?
例:
Col A | Col B --------+--------- Store 1 | 500 Store 2 | 400 Store 3 | 300 ========+========= Total | 1200
您能否帮我获取vba代码以突出显示此列的最小值和最大值?如何使用此流程图创建宏?
例:
Col A | Col B --------+--------- Store 1 | 500 Store 2 | 400 Store 3 | 300 ========+========= Total | 1200
我完全同意,使用MIN & MAX将做的工作条件格式@Peter大号评论顺利, 但是,如果你真的想VBA代码,这种做法可能会做的工作
Sub HighlightMinMax()
Const column As Integer = 2
Dim row As Integer, minRow As Integer, maxRow As Integer
Dim minValue, maxValue
' initialize variables
row = 1
minRow = 1
maxRow = 1
minValue = Cells(row, column)
maxValue = Cells(row, column)
' loop until found "Total" in the first column
While Cells(row, 1) <> "Total"
Debug.Print Cells(row, 1) ' inspect the label
If (Cells(row, column) < minValue) Then
minRow = row
minValue = Cells(row, column)
End If
If (Cells(row, column) > maxValue) Then
maxRow = row
maxValue = Cells(row, column)
End If
row = row + 1
Wend
' select the cell with the min value and highlight it ...changing the background color to green
Cells(minRow, column).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5296274
.TintAndShade = 0
.PatternTintAndShade = 0
End With
' select the cell with the max value and highlight it ...changing the background color to red
Cells(minRow, column).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5296274
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Cells(maxRow, column).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End Sub
难道你不介意与我们分享至少相关的一部分努力 - 只是为了支持[你有什么尝试?](http://whathaveyoutried.com/)其实,你不需要VBA为此 - 使用MIN&MAX进行条件格式化将会执行t他工作顺利。 – 2013-02-17 07:59:17