返回列表 上一主題 發帖

可以幫我寫迴圈並修正錯誤嗎

可以幫我寫迴圈並修正錯誤嗎

本帖最後由 GBKEE 於 2016-1-19 10:17 編輯

Range("K2") 1-140筆資料(可以浮動嗎)
Range("K1") 1--7筆資料(可以浮動嗎)
Sub 完成跑社()
'
' 完成跑社 巨集
''
  Range("K2").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "1"
      Range("K1").Select
      ActiveCell.FormulaR1C1 = "7"
        執行SUB 志願確定
      Range("K1").Select
      ActiveCell.FormulaR1C1 = "6"
        執行SUB 志願確定
      Range("K1").Select
      ActiveCell.FormulaR1C1 = "5"
        執行SUB 志願確定
      Range("K1").Select
      ActiveCell.FormulaR1C1 = "4"
執行SUB 志願確定
      Range("K1").Select
      ActiveCell.FormulaR1C1 = "3"
執行SUB 志願確定
      Range("K1").Select
      ActiveCell.FormulaR1C1 = "2"
執行SUB 志願確定
Range("K1").Select
      ActiveCell.FormulaR1C1 = "1"
      執行SUB 志願確定
Range("K2").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "2"
      Range("K1").Select
      ActiveCell.FormulaR1C1 = "7"
        執行SUB 志願確定
      Range("K1").Select
      ActiveCell.FormulaR1C1 = "6"
        執行SUB 志願確定
      Range("K1").Select
      ActiveCell.FormulaR1C1 = "5"
        執行SUB 志願確定
      Range("K1").Select
      ActiveCell.FormulaR1C1 = "4"
執行SUB 志願確定
      Range("K1").Select
      ActiveCell.FormulaR1C1 = "3"
執行SUB 志願確定
      Range("K1").Select
      ActiveCell.FormulaR1C1 = "2"
執行SUB 志願確定
Range("K1").Select
      ActiveCell.FormulaR1C1 = "1"
      執行SUB 志願確定

End Sub

回復 1# opman

我自己摸索寫成這樣但持行好久,有辦法縮短時間嗎
    Sub 完成跑社()
'
' 完成跑社 巨集
'
Dim s As Integer
For s = 1 To 128
    Range("K2") = s
    Range("K1").Select
    ActiveCell.FormulaR1C1 = "7"
        Columns("F:F").Select
    Selection.Copy
    Range("H1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Selection.Replace What:="N", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Application.CutCopyMode = False
    Selection.Copy
    Range("C1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=True, Transpose:=False
    Range("K1").Select
    ActiveCell.FormulaR1C1 = "6"
        Columns("F:F").Select
    Selection.Copy
    Range("H1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Selection.Replace What:="N", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Application.CutCopyMode = False
    Selection.Copy
    Range("C1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=True, Transpose:=False
    Range("K1").Select
    ActiveCell.FormulaR1C1 = "5"
        Columns("F:F").Select
    Selection.Copy
    Range("H1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Selection.Replace What:="N", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Application.CutCopyMode = False
    Selection.Copy
    Range("C1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=True, Transpose:=False
    Range("K1").Select
    ActiveCell.FormulaR1C1 = "4"
        Columns("F:F").Select
    Selection.Copy
    Range("H1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Selection.Replace What:="N", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Application.CutCopyMode = False
    Selection.Copy
    Range("C1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=True, Transpose:=False
    Range("K1").Select
    ActiveCell.FormulaR1C1 = "3"
        Columns("F:F").Select
    Selection.Copy
    Range("H1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Selection.Replace What:="N", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Application.CutCopyMode = False
    Selection.Copy
    Range("C1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=True, Transpose:=False
    Range("K1").Select
    ActiveCell.FormulaR1C1 = "2"
        Columns("F:F").Select
    Selection.Copy
    Range("H1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Selection.Replace What:="N", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Application.CutCopyMode = False
    Selection.Copy
    Range("C1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=True, Transpose:=False
    Range("K1").Select
    ActiveCell.FormulaR1C1 = "1"
            Columns("F:F").Select
    Selection.Copy
    Range("H1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Selection.Replace What:="N", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Application.CutCopyMode = False
    Selection.Copy
    Range("C1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=True, Transpose:=False
  Next s
End Sub

TOP

        靜思自在 : 【是否發揮了良能?】人間壽命因為短暫,才更顯得珍貴。難得來一趟人間,應問是否為人間發揮了自己的良能,而不要一味求長壽。
返回列表 上一主題