定义动态范围

时间:2017-03-08 08:10:43

标签: excel vba excel-vba

1)我有一张名为C.A.的纸张 我想将范围从B$3复制到最后一个单元格(列为H

2)然后将其粘贴到另一张名为2017的纸张上 到(包含数据的列B的最后一个单元格)下面的2个单元格

我做了第二个,但是,不能定义第一个。

Dim lastRow As String

lastRow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row + 2
Range("B" & lastRow).Select
Selection.PasteSpecial

End Sub

1 个答案:

答案 0 :(得分:0)

试试这个:

Dim ws_ca As Worksheet
Dim ws_17 As Worksheet
Dim nr_2017 As Long
Dim nr_ca As Long

Set ws_ca = ThisWorkbook.Worksheets("C.A.")
Set ws_17 = ThisWorkbook.Worksheets("2017")

nr_ca = ws_ca.Cells(Rows.Count, 8).End(xlUp).Row
nr_2017 = ws_17.Cells(Rows.Count, 2).End(xlUp).Row

ws_17.Range("B" & nr_2017 + 3 & ":H" & nr_2017 + nr_ca).Value = ws_ca.Range("B3:H" & nr_ca).Value