vba 在另一个单元格中输入数据并按 Enter 选项后转到特定单元格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15952263/
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-08 15:22:30  来源:igfitidea点击:

Go To A Particular Cell After Inputting Data In Another Cell And Hitting Enter Options

excelexcel-vbavba

提问by user2270747

I have a Excel sheet and I'm inputting data in A2, B2 and C2; after I hit enter I want the cursor select the next line so I can input information on A3, B3 and C3 and so on

我有一个 Excel 工作表,我在 A2、B2 和 C2 中输入数据;按回车后,我希望光标选择下一行,以便我可以输入有关 A3、B3 和 C3 等的信息

I found this information

我找到了这个信息

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Range("C2").Value <> "" Then
Range("A3").Select
End If
End Sub

But it only works one time, how can I repeat this process over and over

但它只能工作一次,我如何一遍又一遍地重复这个过程

Thanks for your help.....

谢谢你的帮助.....

回答by Siddharth Rout

Another way.

其它的办法。

  1. If you type anywhere in Col A, the selection will move to Col B.
  2. If you type anywhere in Col B, the selection will move to Col C.
  3. If you type anywhere in Col C, the selection will move back to Col A (Next Line).
  1. 如果您在 A 列中的任何位置键入,则选择将移至 B 列。
  2. 如果您在 Col B 中的任何位置键入,则选择将移动到 Col C。
  3. 如果您在 C 列中的任何位置键入,则选择将移回 A 列(下一行)。

Code: This goes in the relevant sheet code area.

代码:这在相关的工作表代码区域中。

Private Sub Worksheet_Change(ByVal Target As Range)
    On Error GoTo Whoa

    Application.EnableEvents = False

    If Not Target.Cells.CountLarge > 1 Then
        If Not Intersect(Target, Columns(1)) Is Nothing Then
            Target.Offset(, 1).Select
        ElseIf Not Intersect(Target, Columns(2)) Is Nothing Then
            Target.Offset(, 1).Select
        ElseIf Not Intersect(Target, Columns(3)) Is Nothing Then
            Target.Offset(1, -2).Select
        End If
    End If
Letscontinue:
    Application.EnableEvents = True
    Exit Sub
Whoa:
    MsgBox Err.Description
    Resume Letscontinue
End Sub

ScreenShot

截屏

enter image description here

在此处输入图片说明

回答by Our Man in Bananas

in your Tools>options dialog what is the settings for Move Selection after Enter?:

在您的工具>选项对话框中,输入后移动选择的设置是什么?:

enter image description here

在此处输入图片说明

there is more information on Tech Republic: Three ways to control Excel's cursor movement during data entrywhich will show you how to do exactly what you want...

有更多关于Tech Republic 的信息:在数据输入过程中控制 Excel 光标移动的三种方法,它将向您展示如何准确地执行您想要的操作...

Basically, select the range cells you want to enter data in, Excel selects the first cell, then after each entry, hit the {Tab} key. Excel will move the carat to the next empty cell in your selection

基本上,选择要输入数据的范围单元格,Excel 选择第一个单元格,然后在每次输入后,点击 {Tab} 键。Excel 会将克拉移动到您选择的下一个空单元格

Voila !

瞧!

回答by Kazimierz Jawor

If you need to involve VBA to that there are to properties which set direction and status respectively:

如果您需要涉及 VBA,则有分别设置方向和状态的属性:

Application.MoveAfterReturnDirection = xlToRight 
Application.MoveAfterReturn = True