返回列表 上一主題 發帖

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

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

附檔的資料是依相同規格去做分組
我想再分組內比較5~8月哪一個交易價格最低
固定區間內的比較容易做到但是不同區間想不到方法
請問有人知道如何作嗎?

最小與最大相同我是用另一個顏色標示





範圍內比較.rar (68.72 KB)
字典兩各字 還真難理解

回復 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

回復 2# GBKEE


    板大可以喔,雖然我只要最小值,但是你連最大值也給了
      有一個問題如果我不想看1-8月我只想看後面幾各月有辦法指定嗎?
    是從cells這邊改嗎?
字典兩各字 還真難理解

TOP

回復 2# GBKEE


    跟原始檔案一樣,一開始我寫想要看5-8月的區間,不過版主直接針對全部做比較
字典兩各字 還真難理解

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

回復 5# GBKEE


    抱歉現在才看
       板主的方式可以
       原來是在一開始的範圍那邊做設定喔
       我想錯方向了
      謝謝
字典兩各字 還真難理解

TOP

        靜思自在 : 君子為目標,小人為目的。
返回列表 上一主題