返回列表 上一主題 發帖

不同的程式寫法

不同的程式寫法

想請教以下這一段程式是否有執行起來比較快的寫法 ?
我只是想參考看看不同的程式寫法.
感謝...
  For fcsty = 4 To put_rownum
            If .Cells(fcsty, "B") <> "" And Not .Cells(fcsty, "A") Like "*合計" Then
               ' 增加判斷 "B"欄為空白, 或是保留 "合計" 的列.
                If .Cells(fcsty, hid_colnum) < put_maxnum And .Cells(fcsty, hid_colnum) > put_minnum Then
                    .Rows(fcsty).Hidden = True
                End If
            End If
        Next
    End With


_________________________________________
整段程式
Sub ProductsQ1FP()
ActiveSheet.PivotTables("樞紐分析表1").PivotFields("Group").ClearAllFilters
ActiveWindow.FreezePanes = False ' 取消凍結視窗
Dim put_rownum As Integer
Dim hid_colnum As Integer
ActiveSheet.Rows.Hidden = False '取消所有的隱藏
ActiveSheet.Range("c4").Select  '游標放在c4
ActiveWindow.FreezePanes = True '凍結視窗
ActiveWindow.ScrollColumn = 3   '凍結列與欄的視窗
ActiveSheet.PivotTables("樞紐分析表1").PivotFields("Group").AutoSort xlDescending, _
    "加總 的Q1F-P"
put_rownum = ActiveSheet.Range("c2").Value  '最後一列
put_maxnum = ActiveSheet.Range("b1").Value  '大於
put_minnum = ActiveSheet.Range("b2").Value  '小於
hid_colnum = ActiveSheet.Range("f1").Value  '排序欄
With ActiveSheet
        .Cells(4, hid_colnum).Select            '游標放置點
        For fcsty = 4 To put_rownum
            If .Cells(fcsty, "B") <> "" And Not .Cells(fcsty, "A") Like "*合計" Then
               ' 增加判斷 "B"欄為空白, 或是保留 "合計" 的列.
                If .Cells(fcsty, hid_colnum) < put_maxnum And .Cells(fcsty, hid_colnum) > put_minnum Then
                    .Rows(fcsty).Hidden = True
                End If
            End If
        Next
    End With
End Sub
fangac

本帖最後由 GBKEE 於 2012-6-17 13:38 編輯

回復 2# register313


    執行有一些問題.
是不是需要宣告Rng變數, 但我加入了Rng變數宣告,也無效.
敬請指點. 謝謝.

Sales by Org.rar (875.75 KB)

fangac

TOP

感謝二位指導.
程式看不太懂,基本功還是需要多練習,好好理解一下,可以應用在別的地方.
fangac

TOP

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