2012-05-15 60 views
0

我是一名首發的VBA愛好者,因此我不想知道如何確保公式適用於所有人書中的行。正如你所看到的,我已經開始複製實際的代碼了,但是由於我必須這樣做最多100行,所以這會過於人工。在Excel中進行復制,同時選取多行,將輸入傳送到複製的Excel公式中

感謝

Sub Charts() 
    ' Charts Macro 
    ' Run charts 
    Range("D7").Value = Range("D11") 
    Range("E7:G7").Select 
    Selection.Copy 
    Range("E11").Select 
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ 
    :=False, Transpose:=False 
    Range("D7").Value = Range("D12") 
    Range("E7:G7").Select 
    Selection.Copy 
    Range("E12").Select 
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ 
     :=False, Transpose:=False 
    Range("D7").Value = Range("D13") 
    Range("E7:G7").Select 
    Selection.Copy 
    Range("E13").Select 
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ 
     :=False, Transpose:=False 
    Range("D7").Value = Range("D14") 
    Range("E7:G7").Select 
    Selection.Copy 
    Range("E14").Select 
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ 
     :=False, Transpose:=False 
End Sub 

回答

1

這是你想什麼呢?

Option Explicit 

Sub Charts() 
    Dim i As Long 

    '~~> Change this to the relevant sheet 
    With Sheets("Sheet1") 
     For i = 11 To 14 '<~~ Change 14 to whatever row you want to go to 
      .Range("D7").Value = .Range("D" & i).Value 

      .Range("E7:G7").Copy 
      .Range("E" & i).PasteSpecial Paste:=xlPasteValues, _ 
      Operation:=xlNone, SkipBlanks:=False, Transpose:=False 
     Next i 
    End With 
End Sub 
+0

謝謝!正是我需要的 – DanielZ