- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
回復 6# cw3076
每一個程序都是依不同需求而量身訂作
- Sub Ex()
- Dim i As Integer, ii As Integer, Rng As Range, A%, x%
- ReDim Ar%(2, A)
- ReDim Xy%(1, x)
- With ActiveSheet.[C:C].SpecialCells(xlCellTypeConstants)
- .Cells(1).CurrentRegion.Sort Key1:=.Cells(1), Header:=xlYes, Order1:=xlAscending
- ' C欄的連續範圍做排序
- If Not ActiveSheet.AutoFilter Is Nothing Then .AutoFilter 'ActiveSheet如有自動篩選 則取消
- For i = Application.Min([C:C]) To Application.Max([C:C])
- .Cells(1).AutoFilter Field:=3, Criteria1:=i ' C欄的連續範圍做自動篩選
- '''''''''修改 Field:= 3 Y為自動篩選的第3個欄位'''''''''
- Set Rng = .SpecialCells(xlCellTypeVisible)
- Set Rng = Rng.Areas(Rng.Areas.Count).Offset(, -1)
- Ar(0, A) = i
- Ar(1, A) = Application.Min(Rng)
- Ar(2, A) = Application.Max(Rng)
- For ii = Ar(1, A) To Ar(2, A)
- If IsError(Application.Match(ii, Rng, 0)) Then
- 'If Rng.Find(ii) Is Nothing Then 改用Match速度 快一些
- Xy(0, x) = ii
- Xy(1, x) = i
- x = x + 1
- ReDim Preserve Xy(1, x)
- End If
- Next
- A = A + 1: ReDim Preserve Ar(2, A)
- Next
- .Cells(1).AutoFilter
- End With
- ActiveSheet.[E2].Resize(A, 3) = Application.Transpose(Ar)
- ActiveSheet.[I2].Resize(x, 2) = Application.Transpose(Xy)
- End Sub
複製代碼 |
|