返回列表 上一主題 發帖

[發問] 如何在不同區間內標示最小值?

回復 1# freeffly
試試看
  1. Option Explicit
  2. Sub Ex()
  3.     Dim i As Single, r As String, xMin As Double, xMax As Double
  4.     Cells.Interior.ColorIndex = xlNone
  5.     i = 2
  6.     r = i
  7.     Do While Cells(i, "a") <> ""
  8.         If Cells(i, "a") <> Cells(i + 1, "a") Then
  9.             With Rows(r & ":" & i)
  10.                 xMin = Application.Min(.Cells)
  11.                 xMax = Application.Max(.Cells)
  12.                 .Cells.Replace xMin, "=err", xlWhole
  13.                 With .SpecialCells(xlCellTypeFormulas, xlErrors)
  14.                     .Cells = xMin
  15.                     .Interior.ColorIndex = IIf(xMin <> xMax, 38, 34)
  16.                 End With
  17.                 If xMin <> xMax Then
  18.                     .Cells.Replace xMax, "=err", xlWhole
  19.                     With .SpecialCells(xlCellTypeFormulas, xlErrors)
  20.                         .Cells = xMax
  21.                         .Interior.ColorIndex = 8
  22.                     End With
  23.                 End If
  24.             End With
  25.             r = i + 1
  26.         End If
  27.         i = i + 1
  28.     Loop
  29. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 4# freeffly
試試看
  1. Option Explicit
  2. Sub Ex()
  3.     Dim i As Single, r As String, xMin As Double, xMax As Double
  4.     Cells.Interior.ColorIndex = xlNone
  5.     i = 2
  6.     r = i
  7.     Do While Cells(i, "a") <> ""
  8.         If Cells(i, "a") <> Cells(i + 1, "a") Then
  9.             With Range("A" & r & ":" & "A" & i).Offset(, 5).Resize(, 4)
  10.               'Offset(, 5) =>A欄到5月的欄數(F欄)
  11.               'Resize(, 4) =>4欄 (5月-8月 )
  12.                 xMin = Application.Min(.Cells)
  13.                 xMax = Application.Max(.Cells)
  14.                 If xMin <> 0 And xMax <> 0 Then
  15.                     .Cells.Replace xMin, "=err", xlWhole
  16.                     With .SpecialCells(xlCellTypeFormulas, xlErrors)
  17.                         .Cells = xMin
  18.                         .Interior.ColorIndex = IIf(xMin <> xMax, 38, 34)
  19.                     End With
  20.                     If xMin <> xMax Then
  21.                         .Cells.Replace xMax, "=err", xlWhole
  22.                         With .SpecialCells(xlCellTypeFormulas, xlErrors)
  23.                             .Cells = xMax
  24.                             .Interior.ColorIndex = 8
  25.                         End With
  26.                     End If
  27.                 End If
  28.             End With
  29.             r = i + 1
  30.         End If
  31.         i = i + 1
  32.     Loop
  33. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 【是否發揮了良能?】人間壽命因為短暫,才更顯得珍貴。難得來一趟人間,應問是否為人間發揮了自己的良能,而不要一味求長壽。
返回列表 上一主題