返回列表 上一主題 發帖

不同的程式寫法

回復 4# register313
  1. Sub ProductsQ1FP()
  2. Dim Rng As Range
  3. ' 12Q1Fcst Vs. Q1Plan
  4. ActiveSheet.PivotTables("樞紐分析表1").PivotFields("Group").ClearAllFilters
  5. ActiveWindow.FreezePanes = False ' 取消凍結視窗
  6. Dim fcsty, put_rownum, hid_colnum, put_maxnum, put_minnum As Integer
  7. ActiveSheet.Rows.Hidden = False '取消所有的隱藏
  8. ActiveSheet.Range("c4").Select  '游標放在c4
  9. ActiveWindow.FreezePanes = True '凍結視窗
  10. ActiveWindow.ScrollColumn = 3   '凍結列與欄的視窗
  11. ActiveSheet.PivotTables("樞紐分析表1").PivotFields("Group").AutoSort xlDescending, _
  12.     "加總 的Q1F-P"
  13. ' 樞紐分析以加總的Q1F-P做排序
  14. put_rownum = ActiveSheet.Range("a1").Value  '最後一列
  15. put_maxnum = ActiveSheet.Range("b1").Value  '大於
  16. put_minnum = ActiveSheet.Range("b2").Value  '小於
  17. hid_colnum = ActiveSheet.Range("f1").Value  '排序欄
  18. With ActiveSheet
  19.   For fcsty = 4 To put_rownum
  20.     If .Cells(fcsty, "B") <> "" And Not .Cells(fcsty, "A") Like "*合計" Then
  21.        If .Cells(fcsty, hid_colnum) < put_maxnum And .Cells(fcsty, hid_colnum) > put_minnum Then
  22.          If Rng Is Nothing Then
  23.             Set Rng = .Range("A" & fcsty)
  24.         Else
  25.             Set Rng = Union(Rng, .Range("A" & fcsty))
  26.         End If
  27.        End If
  28.     End If
  29.   Next
  30.   .Rows("4:" & put_rownum).Hidden = False
  31. End With
  32. Rng.EntireRow.Hidden = True
  33. End Sub
複製代碼

TOP

回復 6# register313
範圍如可預知    Rng = IIf(Rng = "", "A" & fcsty, Rng & "," & "A" & fcsty) 是簡單些

TOP

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