2014-07-02 88 views
-2

在工作簿中,我有兩個表格;包含計算公式的TAB1和包含要計算的數據的TAB2。複製單元格範圍x次

範圍TAB1.cells(1,1):範圍TAB1.cells(20,1)包含公式並需要複製到右側x次。

Range TAB1.cells(25,1):範圍TAB1.cells(25,x)包含公式並需要向下複製y次。

而X =列數與

我曾嘗試使用以下VBA在TAB2在TAB2 而Y =與數據行的數量的數據,但我收到錯誤:

Sub DataCopy() 
Dim RowMax As Integer 
Dim ColMax As Integer 

    Sheets("Data").Select 
    Range("A1").Select 

    RowMax = Cells(Rows.Count, 1).End(xlUp).Row 
    ColMax = Cells(2, Columns.Count).End(xlToRight).Column 

    Range(1, 1).Select 
    Range(RowMax, ColMax).Select 

    Selection.Copy 
    Sheets("Calc").Select 
    Range("A1").Select 
    ActiveSheet.Paste 
    Range("A1").Select 

End Sub 

謝謝你的幫助!

+0

這不是一個問題,而是一系列的需求。什麼*正確*阻止你這樣做?你嘗試過什麼(包括現有的代碼),發生了什麼? –

+0

只需在錄製宏時錄製,保存並在需要時重新運行。 – hnk

+0

感謝您的意見。我創建了一個宏,並嘗試使用它創建一個VBA。但我收到一個錯誤。 我已將代碼添加到我的問題中,以便更好地閱讀。 – alphaService

回答

0

試試這個:

Sub DataCopy() 
    Dim RowMax As Integer 
    Dim ColMax As Integer 

    RowMax = Cells(Rows.Count, 1).End(xlUp).Row 
    ColMax = Cells(2, Columns.Count).End(xlToLeft).Column 

    Range(Cells(1, 1),Cells(RowMax,ColMax)).Copy 
    Sheets("Calc").Paste 
    Application.CutCopyMode = FALSE 
End Sub 
相關問題