2012-11-16 190 views
0

你好其他程序員, 我遇到了Excel中VBA編碼的問題。我的問題是將數據從VBA中的單元格範圍複製到VBA中的其他單元格範圍。這裏是例子的子過程我有...Excel VBA單元格範圍副本rountine

Public Sub CopyRange(ByVal pv_ws_source_worksheet As Worksheet, _ 
       ByVal pv_ws_destination_worksheet As Worksheet, _ 
       ByVal pv_rg_source_range As Range, _ 
       ByVal pv_rg_destination_range As Range) 

    Dim Cell_Range As Range 
    Dim CommaSplit() As String 
    Dim ColonSplit() As String 
    Dim i As Integer 
    Dim j As Integer 

    CommaSplit() = Split(pv_rg_destination_range.Address, ",") 

    For Each Cell_Range In pv_ws_source_worksheet.Range(pv_rg_source_range.Address) 
     pv_ws_destination_worksheet.Range(CommaSplit(i)).Value = Cell_Range.Value 
     i = i + 1 
    Next 

End Sub 

此子目前可以複製單元格的範圍像B17:B24到indiviual細胞像B25,B18,B22,B21,B11,A12,A2,C2 。我需要修改這個子集,以便它可以將單元格區域複製到其他單元格區域。這個想法的一個例子是B24:B30到C12:C17,它們可以在不同的工作表上。請幫助,我會大大appericate它:)

回答

1

你正在推翻這一點。你可以做一個簡單的:

Worksheet1.Range("something").Copy 
Worksheet2.Range("something").PasteSpecial xlPasteValues 
'If needed add this for formatting 
'Worksheet2.Range("something").PasteSpecial xlPasteFormat 
+0

不與我抄襲,我收到了1004錯誤有關 – user1750089

+1

由於錯誤消息說,「那命令不能對多重選擇使用」的單元格區域的工作,你可以」 t使用多個選項。在進行復制粘貼之前分解您的範圍。 – ApplePie

相關問題