2014-04-06 123 views
1

我對VBA for Excel非常陌生,並且羞於承認我不明白迄今爲止我讀過的東西! 我試圖從一張紙複製並粘貼到另一張紙上,然後將第二張紙的結果重新複製回第一張紙。我有大約5300件我希望複製的項目 - 從原始工作表中粘貼。這是錄製的宏導致:在excel中重複宏

Sub Retreive_Code() 
    Range("L11").Select 
    Selection.Copy 
    Windows(_ 
     "Unique License plate Valuation Algorithm.18March2014.V7.0.Winner!.xlsx"). _ 
     Activate 
    Range("D2").Select 
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ 
     :=False, Transpose:=False 
    Range("L2").Select 
    Application.CutCopyMode = False 
    Selection.Copy 
    Windows("Complete Unique number sales.2010 - 2012.xlsx").Activate 
    Range("M11").Select 
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ 
     :=False, Transpose:=False 
End Sub 

請讓我知道你是否有任何問題。 非常感謝

+0

'請讓我知道如果您有任何all'問題 - 我們沒有任何問題。你有問題嗎? –

+0

我當然可以!我需要知道如何使用VBA在整個列中複製此公式。 – user3503230

+0

您想要複製哪些範圍以及需要粘貼的位置? –

回答

2

請避免使用.Select/.ActivateINTERESTING READ

這是你想什麼呢?

UNTESTED

Sub Retreive_Code() 
    Dim wb1 As Workbook, wb2 As Workbook 
    Dim ws1 As Worksheet, ws2 As Worksheet 

    '~~> Set your workbooks here 
    Set wb1 = Workbooks("Unique License plate Valuation Algorithm.18March2014.V7.0.Winner!.xlsx") 
    Set wb2 = Workbooks("Complete Unique number sales.2010 - 2012.xlsx") 

    '~~> Change these to the respective sheets 
    Set ws1 = wb1.Sheets("Sheet1") 
    Set ws2 = wb2.Sheets("Sheet1") 

    '~~> Do the copy pasting 
    With ws2 
     ws1.Range("D12:D5283").Value = .Range("L12:L5283").Value 

     DoEvents 

     .Range("M12:M5283").Value = ws1.Range("L12:L5283").Value 
    End With 
End Sub 
+1

'Range1.Value = Range2 .Value' imo比複製粘貼等效大小的範圍要好。否則,一個乾淨的答案:) –

+0

真@Cor_Blimey。更新:) –