標題:
[發問]
如何在不同區間內標示最小值?
[打印本頁]
作者:
freeffly
時間:
2014-10-2 13:22
標題:
如何在不同區間內標示最小值?
附檔的資料是依相同規格去做分組
我想再分組內比較5~8月哪一個交易價格最低
固定區間內的比較容易做到但是不同區間想不到方法
請問有人知道如何作嗎?
最小與最大相同我是用另一個顏色標示
[attach]19267[/attach]
作者:
GBKEE
時間:
2014-10-3 07:05
回復
1#
freeffly
試試看
Option Explicit
Sub Ex()
Dim i As Single, r As String, xMin As Double, xMax As Double
Cells.Interior.ColorIndex = xlNone
i = 2
r = i
Do While Cells(i, "a") <> ""
If Cells(i, "a") <> Cells(i + 1, "a") Then
With Rows(r & ":" & i)
xMin = Application.Min(.Cells)
xMax = Application.Max(.Cells)
.Cells.Replace xMin, "=err", xlWhole
With .SpecialCells(xlCellTypeFormulas, xlErrors)
.Cells = xMin
.Interior.ColorIndex = IIf(xMin <> xMax, 38, 34)
End With
If xMin <> xMax Then
.Cells.Replace xMax, "=err", xlWhole
With .SpecialCells(xlCellTypeFormulas, xlErrors)
.Cells = xMax
.Interior.ColorIndex = 8
End With
End If
End With
r = i + 1
End If
i = i + 1
Loop
End Sub
複製代碼
作者:
freeffly
時間:
2014-10-3 10:27
回復
2#
GBKEE
板大可以喔,雖然我只要最小值,但是你連最大值也給了
有一個問題如果我不想看1-8月我只想看後面幾各月有辦法指定嗎?
是從cells這邊改嗎?
作者:
freeffly
時間:
2014-10-6 10:23
回復
2#
GBKEE
跟原始檔案一樣,一開始我寫想要看5-8月的區間,不過版主直接針對全部做比較
作者:
GBKEE
時間:
2014-10-7 11:45
回復
4#
freeffly
試試看
Option Explicit
Sub Ex()
Dim i As Single, r As String, xMin As Double, xMax As Double
Cells.Interior.ColorIndex = xlNone
i = 2
r = i
Do While Cells(i, "a") <> ""
If Cells(i, "a") <> Cells(i + 1, "a") Then
With Range("A" & r & ":" & "A" & i).Offset(, 5).Resize(, 4)
'Offset(, 5) =>A欄到5月的欄數(F欄)
'Resize(, 4) =>4欄 (5月-8月 )
xMin = Application.Min(.Cells)
xMax = Application.Max(.Cells)
If xMin <> 0 And xMax <> 0 Then
.Cells.Replace xMin, "=err", xlWhole
With .SpecialCells(xlCellTypeFormulas, xlErrors)
.Cells = xMin
.Interior.ColorIndex = IIf(xMin <> xMax, 38, 34)
End With
If xMin <> xMax Then
.Cells.Replace xMax, "=err", xlWhole
With .SpecialCells(xlCellTypeFormulas, xlErrors)
.Cells = xMax
.Interior.ColorIndex = 8
End With
End If
End If
End With
r = i + 1
End If
i = i + 1
Loop
End Sub
複製代碼
作者:
freeffly
時間:
2014-10-30 15:17
回復
5#
GBKEE
抱歉現在才看
板主的方式可以
原來是在一開始的範圍那邊做設定喔
我想錯方向了
謝謝
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)