相关文章推荐
被表白的饺子  ·  mysql show master ...·  3 周前    · 
近视的金鱼  ·  如何在flutter ...·  8 月前    · 
发财的西红柿  ·  RxJava2 Flowable ...·  1 年前    · 

對於開發跨 多個平台 ,擴充使用者 Office 體驗的解決方案感到興趣嗎? 請參閱新的 Office 增益集模型 。 與 VSTO 增益集和解決方案相比,Office 增益集的佔用空間較小,而且您可以使用幾乎任何網頁程式技術 (例如 HTML5、JavaScript、CSS3 和 XML) 來建立這些增益集。

expression . Copy ( Destination )

expression 代表 Range 物件的變數。

必要/選用

以下範例會將 Sheet1 上 A1:D4 儲存格的公式複製到 Sheet2 上的 E5:H8 儲存格中。

Worksheets("Sheet1").Range("A1:D4").Copy _ 
    destination:=Worksheets("Sheet2").Range("E5:H8")

下列程式碼範例會針對 Sheet1 上每一列,逐一檢查 D 欄的值。 如果 D 欄中的值等於 A,則會將整列複製到 SheetA 的下一個空白列中。 如果值等於 B ,則會將列複製到 SheetB。

Public Sub CopyRows() 
    Sheets("Sheet1").Select 
    ' Find the last row of data 
    FinalRow = Cells(Rows.Count, 1).End(xlUp).Row 
    ' Loop through each row 
    For x = 2 To FinalRow 
        ' Decide if to copy based on column D 
        ThisValue = Cells(x, 4).Value 
        If ThisValue = "A" Then 
            Cells(x, 1).Resize(1, 33).Copy 
            Sheets("SheetA").Select 
            NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1 
            Cells(NextRow, 1).Select 
            ActiveSheet.Paste 
            Sheets("Sheet1").Select 
        ElseIf ThisValue = "B" Then 
            Cells(x, 1).Resize(1, 33).Copy 
            Sheets("SheetB").Select 
            NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1 
            Cells(NextRow, 1).Select 
            ActiveSheet.Paste 
            Sheets("Sheet1").Select 
        End If 
    Next x 
End Sub

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應