我正在尝试存储所选单元格的左上角。之后,下面的代码选择了很多不同的区域,在执行之后,我想让选定的单元格成为最初选择的单元格的左上角。
我在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
有人能指出我正确的方向吗/请更正我的编码吗?
答案 0 :(得分:2)
当您在With ... End With statement内时,所有以句点(又名.
或句号)开头的内容都与Selection
的{{1}}直接相关With ... end With block references。
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)
内部是指选区左上角的单元格。< / p>