- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
5#
發表於 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
複製代碼 |
|