返回列表 上一主題 發帖

[發問] 利用VBA隱藏特定數值的列(Row) 和排序(Sort)

回復 1# ipip207
試試看
最上面插入一列
由左至右依序填入 ByDate,Show,Hide,Jan,Feb, Mar, ...,Dec
  1. Private Sub Worksheet_selectionChange(ByVal Target As Range)
  2.     Dim Col%, LstR%, Rng As Range
  3.     Col = Target.Column
  4.     If Col > 15 Then Exit Sub
  5.     LstR = [A65536].End(xlUp).Row
  6.     Set Rng = Range([A2], Cells(LstR, 15))     '全部排序範圍
  7.     If Target.Row > 1 Then Exit Sub
  8.     If Col = 1 Then       'Sort byDate xlAscending(恢復原狀)
  9.         Rng.Sort _
  10.             Key1:=Range("A2"), Order1:=xlAscending, _
  11.             Header:=xlYes
  12.     ElseIf Col = 2 Then
  13.         Cells.EntireRow.Hidden = False
  14.     ElseIf Col = 3 Then
  15.         For I = 3 To LstR
  16.             If Cells(I, 3).Value > 2 Then
  17.                 Cells(I, 3).EntireRow.Hidden = True
  18.             End If
  19.         Next
  20.     Else
  21.         Set Rng = Range([A2], Cells(LstR, 15))     '全部排序範圍, 6代表"F"
  22.         Rng.Sort _
  23.             Key1:=Cells(2, Col), Order1:=xlDescending, _
  24.             Header:=xlYes
  25.     End If
  26. End Sub
複製代碼
20170217.gif

TOP

        靜思自在 : 【停滯不前,終無所得】人都迷於尋找奇蹟,因而停滯不前;縱使時間再多、路再長,也了無用處,終無所得。
返回列表 上一主題