dynamic范围压缩成一行代码

我试图找出最简洁的方法来创build一个dynamic范围,我认为,这是接近我想要做的,但我不知道如何使其正确。 有什么想法吗?

Sub Macro1() Dim RNG As Range With Sheets("Open Jobs Report") 'Change to your sheet Set RNG = .Range("A1", .Cells(.Cells(.Rows.Count, "A").End(xlUp).Row, .Cells(1, .Columns.Count).End(xlToLeft).Column)) End With 

尝试这个:

 Dim RNG As Range Set RNG = .Range("A1", .Cells(.Cells(.Rows.Count, "A").End(xlUp).Row, .Cells(1, .Columns.Count).End(xlToLeft).Column)) 

因为你在用. 在一些范围对象的前面,我认为它是在这样一个With Block中:

 Sub foooooii() Dim RNG As Range With Sheets("Sheet3") 'Change to your sheet Set RNG = .Range("A1", .Cells(.Cells(.Rows.Count, "A").End(xlUp).Row, .Cells(1, .Columns.Count).End(xlToLeft).Column)) End With Debug.Print RNG.Address End Sub 

build立在斯科特的解决scheme,只是为了缩短一点:

 Set RNG = .Range(.Cells(.Rows.Count, "A").End(xlUp), .Cells(1, .Columns.Count).End(xlToLeft))