vba EXCEL:粘贴后将焦点设置在特定单元格上

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14507592/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 19:20:42  来源:igfitidea点击:

EXCEL: Set focus on specific cell after pasting

excelvba

提问by Parseltongue

Should be a simple question:

应该是一个简单的问题:

I have the following script which pastes data:

我有以下粘贴数据的脚本:

Dim a As Range
Set a = Selection
Selection.Cut
Range("C1:I1").End(xlDown).Offset(1, 0).Select
ActiveSheet.Paste

Upon pasting, the ActiveSheet moves to the cell in which its pasting in. How do I re-focus on the cell from which the data was cut?

粘贴后,ActiveSheet 将移动到其粘贴所在的单元格。如何重新关注从中剪切数据的单元格?

I want to put the focus on the Range that is currently held in the 'A' variable.

我想将重点放在当前保存在“A”变量中的范围上。

I tried this:

我试过这个:

a.Select

And

a.Activate

but, it doesn't actually move the activeSheet to the correct area; it just selects it.

但是,它实际上并没有将 activeSheet 移动到正确的区域;它只是选择它。

回答by tbur

What you seem to want can be accomplished in a single line:

您似乎想要的内容可以在一行中完成:

Sub OneLiner()
   Selection.Cut Range("C1:I1").End(xlDown).Offset(1, 0)
End Sub

A single space after the cutkeyword means the destination follows.

cut关键字后的单个空格表示目的地在后面。

There's no need to Dim or Set a, as you're not even using aas a variable in your code.

不需要 Dim 或 Set a,因为您甚至没有在代码中使用a作为变量。

Doing it this way does not use the clipboard, change the position of the cursor or page location.

这样做不使用剪贴板,更改光标位置或页面位置。