VBA找出每列的最大值和最小值并且分别用红色和黄色标出来解决方法
VBA找出每列的最大值和最小值并且分别用红色和黄色标出来
怎么有错啊
------解决方案--------------------
可以用条件格式,试试这个
Range("D1:D24").FormatConditions.Delete
Range("D1:D24").FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=MAX($D$1:$D$24)"
Range("D1:D24").FormatConditions(1).Font.ColorIndex = 3
Range("D1:D24").FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=MIN($D$1:$D$24)"
Range("D1:D24").FormatConditions(2).Font.ColorIndex = 6
------解决方案--------------------
Range("D1:D24").FormatConditions.Delete
Range("D1:D24").FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=MAX($D$1:$D$24)"
Range("D1:D24").FormatConditions(1).Interior.ColorIndex = 3
Range("D1:D24").FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=MIN($D$1:$D$24)"
Range("D1:D24").FormatConditions(2).Interior.ColorIndex = 6
不错呀!
------解决方案--------------------
------解决方案--------------------
其实不用VBA找啊,你可以直接用条件格式实现。
------解决方案--------------------
你只需要选中A列,然后条件格式中选择公式,输入 =A1=max(A:A)
然后把格式复制到其它所有需要的列就可以了。
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
不好意思,忘记了后面的公式,更正一下:
怎么有错啊
- VB code
Sub GetMax() Range.Find(Application.WorksheetFunction.Max(Range("D1:D24"))).Activate ActiveSheet.Cells(1, 1).Interior.ColorIndex = 3 End Sub
------解决方案--------------------
可以用条件格式,试试这个
Range("D1:D24").FormatConditions.Delete
Range("D1:D24").FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=MAX($D$1:$D$24)"
Range("D1:D24").FormatConditions(1).Font.ColorIndex = 3
Range("D1:D24").FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=MIN($D$1:$D$24)"
Range("D1:D24").FormatConditions(2).Font.ColorIndex = 6
------解决方案--------------------
Range("D1:D24").FormatConditions.Delete
Range("D1:D24").FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=MAX($D$1:$D$24)"
Range("D1:D24").FormatConditions(1).Interior.ColorIndex = 3
Range("D1:D24").FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=MIN($D$1:$D$24)"
Range("D1:D24").FormatConditions(2).Interior.ColorIndex = 6
不错呀!
------解决方案--------------------
------解决方案--------------------
其实不用VBA找啊,你可以直接用条件格式实现。
------解决方案--------------------
你只需要选中A列,然后条件格式中选择公式,输入 =A1=max(A:A)
然后把格式复制到其它所有需要的列就可以了。
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
不好意思,忘记了后面的公式,更正一下:
- VBScript code
Sub Main() Dim i&, strCh$, strRange$ For i = 1 To 150 '对前150列加条件格式 If (i < 27) Then strCh = Chr$(64 + i) Else strCh = Chr$(65 + (i - 1) \ 26) & Chr$(65 + (i - 1) Mod 26) End If strRange = strCh & "1:" & strCh & "24" Range(strRange).FormatConditions.Delete Range(strRange).FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="=MAX($" & strCh & "$1:$" & strCh & "$24)" Range(strRange).FormatConditions(1).Font.ColorIndex = 3 Range(strRange).FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="=MIN($" & strCh & "$1:$" & strCh & "$24)" Range(strRange).FormatConditions(2).Font.ColorIndex = 6 Next End Sub
------解决方案--------------------
To 19F:
在 strRange = strCh & "1:" & strCh & "24"’strRange用来做什么? 之前的“疑问”:
这根本不应该算“疑问”,你要不是明白,只要在这句前加个:
Debug.Print i, strCh