Sub main()
Dim rng_whole As Range
Set rng_whole = rng_return_whole_rng()
rng_whole.select
End Sub
Function rng_return_whole_rng() As Range
Dim rng_start_cells, rng_end_cells, rng_whole As Range
Set rng_start_cells = Cells(1, 1)
Set rng_end_cells = Cells(1, 1).End(xlToRight).End(xlDown)
Set rng_whole = Range(rng_start_cells, rng_end_cells)
Set rng_return_whole_rng = rng_whole
End Function
工作中常常要使用VBA复制粘贴一整张表,而这个时候,选中一整张表的操作就显得非常必要。
为了代码的美观和易维护性,我们可以把获取表的整个区域写成一个函数,并且通过这个函数返回这个区域,使得外部的range变量可以取得这个值,不管是select,还是copy都非常方便。
网友评论