如何存储select框左上angular的位置

我试图存储所选单元格的左上angular。 之后,下面的代码select了很多不同的区域,在执行它之后,我想让选定的单元格位于最初选定的单元格的左上angular。

With Selection后出现错误:

 Private Sub Test() Dim InsertPoint As Range With Selection Set InsertPoint = Range(.Row, .Column) 'insert a bunch of code working with this selection End With 'insert a whole wack of code selecting various things InsertPoint.select End Sub 

有人能指出我正确的方向/纠正我的编码吗?

当您在With … End With语句中时 ,以句号开头(aka .句号 )的所有内容将与With … end With块引用的Selection直接相关。

 With Selection Set InsertPoint = .Cells(1) debug.print InsertPoint.address(0, 0) 'do lots of stuff here End With debug.print InsertPoint.address(0, 0) 

因此, Cells(1)Cells(1, 1)仍将引用工作表的A1,但在该块内部.Cells(1)引用select区域左上angular的单元格。