返回列表 上一主題 發帖

[發問] 請問此段巨集如何簡化或加快速度??

回復 1# t8899
此兩個可否放在with 裡面,試試看吧!
  1. Option Explicit
  2. Sub zzzzz()
  3. Application.ScreenUpdating = False
  4. Application.EnableEvents = False
  5. Application.DisplayStatusBar = False
  6. ActiveSheet.DisplayPageBreaks = False
  7. With Sheets("Sheet1")
  8.      .Range("B65536").End(xlUp).Offset(1) = .Range("D16").Value
  9.      .Range("O65536").End(xlUp).Offset(1) = .Range("C16").Value
  10.      .Range("P65536").End(xlUp).Offset(1) = .Range("C18").Value
  11.      .Range("Q65536").End(xlUp).Offset(1) = .Range("B16").Value
  12. End With
  13. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

本帖最後由 GBKEE 於 2013-9-6 12:42 編輯

回復 3# t8899
另外 下面兩個可否放在with 裡面   試試就知道(你試過嗎?)
是否非同一個物件? 請再說明白
  1. Option Explicit 陳述式
  2. 在模組層次中強迫每個在模組�堛瘍僂くㄔ眸楨�確的宣告。
  3. 語法
  4. Option Explicit
  5. 請注意
  6. Option Explicit 陳述式必出現在模組�堙A且在任何程序之前。
  7. 當 Option Explicit 在模組中使用時,必須以 Dim, Private、Public、ReDim 或 Static 陳述式來明確宣告所有的變數。如果使用未宣告的變數名稱,則在編譯階段時,會發生錯誤。
  8. 如果未使用 Option Explicit 陳述式,則所有未宣告的變數都是 Variant 型態,除非預設的型態另以 Deftype 陳述式所指定過。
  9. 附註 Option Explicit 可避免打錯變數名稱或在有效範圍內相同的變數名稱。
複製代碼
  1. Option Explicit
  2. Sub Ex()
  3.     [F8:F14].Clear
  4.     With Range("D4")
  5.         .Cells = "=888"
  6.         .NoteText "註解文字"                                     '註解
  7.         .Interior.ColorIndex = 8
  8.         .Copy Range("F8")                                        '全部
  9.         Range("F9").Value = .Value                               '值
  10.         Range("F10").Formula = .Formula                          '公式
  11.         Range("F11").NumberFormatLocal = .NumberFormatLocal      '數字格式
  12.         Range("F12").Interior.ColorIndex = .Interior.ColorIndex  '圖樣 色彩
  13.         Range("F13") = .Value
  14.         Range("F13").Font.Size = .Font.Size + 2                  '字型大小
  15.         Range("F14").NoteText .NoteText                          '註解
  16.     End With
  17. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 5# t8899
  1. For i = 350 To 21 Step -1
  2.   If IsError(Cells(i, "h")) Then Run "clear": Exit For
  3. next
複製代碼
IsError(Cells(i, "h"))  是 With Sheets("Sheet1") 裡的Cells(i, "h") 嗎?,
不是要指明工作表  IsError(Sheets("工作表名稱").Cells(i, "h"))

Run "clear"  這是 VBA的關鍵字 Clear 方法,最好換個字串
另外 Run 的程序在物件模組(不在一般模組裡)      要指明模組 Run "Sheet1.程序"
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 7# t8899
是With Sheets("Sheet1") 裡的Cells(i, "h") 就可用With. (快不快??? 不知你的想法)
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 9# t8899
就這樣多練習,會進步的
更正(燒餅吃多了)
  1. Range("F11").NumberFormatLocal = .NumberFormatLocal      '數字格式
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 11# acdx
  1. Option Explicit
  2. Private Sub format()
  3.     Dim ws As Worksheet, sName As String, AR(1 To 2), I As Integer
  4.     sName = "PTAVS"
  5.     On Error Resume Next
  6.     Set ws = Sheets(sName)
  7.     If ws Is Nothing Then
  8.         Worksheets.Add after:=Worksheets(Worksheets.Count)
  9.         Worksheets(Worksheets.Count).Name = sName
  10.         Set ws = Sheets(sName)
  11.     Else
  12.         MsgBox sName & "工作表已存在。"
  13.         Sheets("Result").Select
  14.         Exit Sub
  15.     End If
  16.     With ws.Cells
  17.         .HorizontalAlignment = xlCenter
  18.         .VerticalAlignment = xlCenter
  19.         .Orientation = 0
  20.         .AddIndent = False
  21.         .IndentLevel = 0
  22.         .ShrinkToFit = False
  23.         .ReadingOrder = xlContext
  24.         .MergeCells = False
  25.         With .Font
  26.             .Name = "Arial"
  27.             .Size = 10
  28.             .Strikethrough = False
  29.             .Superscript = False
  30.             .Subscript = False
  31.             .OutlineFont = False
  32.             .Shadow = False
  33.             .Underline = xlUnderlineStyleNone
  34.             .ColorIndex = xlAutomatic
  35.             .TintAndShade = 0
  36.             '.ThemeFont = xlThemeFontNone  '2003沒這參數
  37.         End With
  38.         .Range("B1:M1").Merge
  39.         AR(1) = Array("A1:A4", "B2:G2", "B3:D3", "E3:G3", "B4:G4")
  40.         AR(2) = Array("C1~C5", "(sone)", "H", "M", "")
  41.         For I = 0 To UBound(AR(1))
  42.             With .Range(AR(1)(I))
  43.                 .WrapText = False
  44.                 .MergeCells = IIf(I < UBound(AR(1)), True, False)
  45.                 .Value = AR(2)(I)
  46.             End With
  47.         Next
  48.         .Range("B4:D4").Value = Array("mean", "standard deviation", "mean+CV*stdev")
  49.         .Range("B4:D4").Copy .Range("E4")
  50.         .Range("B2:G4").Copy .Range("H2")
  51.         .Range("H2").Value = "(tu)"
  52.         With .Range("A1:M4")
  53.             For I = 5 To 12   '畫框線
  54.                 With .Borders(I)
  55.                     .LineStyle = IIf(I >= 7, xlContinuous, xlNone)
  56.                     If I >= 7 Then .ColorIndex = 0
  57.                     'If I >= 7 Then .TintAndShade = 0       '2003框線沒這屬性
  58.                     If I >= 7 Then .Weight = xlThin
  59.                 End With
  60.             Next
  61.             .Font.Name = "Arial"
  62.             .Font.Size = 10
  63.         End With
  64.     End With
  65.     Sheets("Result").Select
  66. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 13# acdx
工具書一般都是一樣的,多看多練習,日久候一定可以替後人解惑的.
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 成功是優點的發揮,失敗是缺點的累積。
返回列表 上一主題