我使用以下VBA来选择一个单元格块然后复制它。但是,结果显示Excel 仅 复制该块中的 last 单元格。为什么?怎么修?感谢。
Sheets(1).Select
Range("B8").Activate
ActiveCell.End(xlDown).End(xlToRight).Select
Selection.Copy
更新
我想出了另一种解决方法(可能不是很聪明):
Sheets(1).Select
Range("B8").Select
ActiveCell.End(xlDown).End(xlToRight).Select
Selection.Name = "LastCell"
Range("B8", "LastCell").Select
Selection.Copy
答案 0 :(得分:2)
使用此:
Dim ws As Worksheet
Dim nr_rows As Long
Set ws = ThisWorkbook.Worksheets("1")
With ws
nr_rows = ws.Range("B1048576").End(xlUp).Row
ws.Range("B8:B" & nr_rows).Copy
End With
如果你想要selection
Sheets("1").Select
Range("B8").Activate
Range(ActiveCell, Cells(ActiveCell.End(xlDown).Row, ActiveCell.End(xlToRight).Column)).Select
Selection.Copy
或者在一行中:
Sheets("1").Range(Cells(8, 2), Cells(ActiveCell.End(xlDown).Row, ActiveCell.End(xlToRight).Column)).Select