最初选择的单元格存储在rngStart
最后重新选择,这样用户就不会被宏带走。但是,存储在的范围rngStart
变化。看来是单独的。它最终成为粘贴操作发生的范围。
Sub Macro2()
Application.ScreenUpdating = False
Dim rngStart 'The variable I'm struggling with
Dim ws As Worksheet
Set rngStart = Selection 'Store original selection
Set ws = ActiveSheet
Selection.Cut
'Find an empty cell in column B
For Each cell In ws.Columns(2).Cells
If IsEmpty(cell) = True Then cell.Select: Exit For
Next cell
ActiveSheet.Paste 'Upon executing this line, rngStart changes to the cell being pasted to
rngStart.Select 'Supposed to return to the originally selected range
Application.ScreenUpdating = True
End Sub
将其保存为字符串。
Sub Macro2()
Application.ScreenUpdating = False
Dim rngStart As String 'The variable I'm struggling with
Dim ws As Worksheet
rngStart = Selection.Address 'Store original selection
Set ws = ActiveSheet
Selection.Cut
'Find an empty cell in row B
For Each cell In ws.Columns(2).Cells
If IsEmpty(cell) = True Then cell.Select: Exit For
Next cell
ActiveSheet.Paste 'Upon executing this line, rngStart changes to the cell being pasted to
Range(rngStart).Select 'Supposed to return to the originally selected range
Application.ScreenUpdating = True
End Sub
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)