如何限制 Ctrl +以 Excel 工作表结束

发布于 2024-12-03 08:27:20 字数 293 浏览 0 评论 0原文

我在第 500 - 503 行插入了一些数据。我故意将数据放置在这些行中,因为这些行将在宏中使用,而不是在用户视图中使用。与用户相关的数据在第100行结束。

我隐藏了第500 - 503行,但按Ctrl + End后,光标移动到第499行。

我的要求是按Ctrl + End后,光标应该在最后第 100 行的单元格。

那么,我该怎么做?

编辑:感谢您的所有回答。许多人建议我再准备一张非用户相关数据的表,但我没有。另外我不应该有 vba 脚本。(应该之前给你这些条件......我的错!)

I have some data inserted at Rows 500 - 503. I placed the data intentionally at those rows because these rows will be used in Macro's and not for User's view. The data concerned to the user ends at Row 100.

I have hidden the Rows 500 - 503, yet after hitting Ctrl + End, the Cursor moves to Row 499.

My requirement is after hitting Ctrl + End, the Cursor should be at the last cell of Row 100.

So, how do i do this ?

EDIT : Thanks for all the answers. Many advised me to have another sheet for non user related data, but i can't have it. Also i am not supposed to have the vba scripts.(Should have given you these conditions before... my bad!)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

素年丶 2024-12-10 08:27:20

通过更好的隔离可以解决这个问题。

也就是说,设计供用户使用的工作表应限制为仅包含用户界面所需的元素。在这种情况下,只有用户应该看到的行。

任何需要保留在并非为用户直接使用而设计的工作表中的数据都应该位于其自己的工作表上,甚至可以对用户完全隐藏。

This problem will be removed with better isolation.

That is, worksheets which are designed for use by a user should be restricted to containing only the elements necessary for the user interface. In this case, only the rows which the user is supposed to see.

Any data which needs to be persisted in worksheets which is not designed for direct user consumption should be on their own worksheets, which can even be hidden from the user completely.

述情 2024-12-10 08:27:20

当然,您问题的具体答案是:捕获 Ctrl-END 键的使用。

您可以通过在工作表中指定以下事件触发器来轻松完成此操作:

Private Sub Worksheet_Activate()
    Application.OnKey "^{END}", "SuppressMe"
End Sub

Private Sub Worksheet_Deactivate()
    Application.OnKey "^{END}", ""
End Sub

另一个模块包含

Sub SuppressMe()
    ' you can be very creative here about line 100 or not 100
    MsgBox "Co-Cooooo :-P"
End Sub

另一个满足您所描述的要求并消除观察和抑制按键的需要的可爱方法是将导航限制为第 100 行。现在是 Ctrl-END会将用户置于第 100 行的最右列,并且 Ctrl-DOWN 也会被覆盖。事实上,用户无法越过第 100 行

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Row > 100 Then
        Me.Cells(100, Target.Column).Select
    End If
End Sub

,但是......等等!难道真的没有办法了吗? ...当然,用户仍然可以滚动超过第 100 行并检测到您的小第 500 行复活节彩蛋。因此,我 100% 同意之前关于不同策略的建议,因为

  • 用户发现第 500 - 503 行被隐藏,可能会变得非常好奇为什么
  • Ctrl-END 不是用户可以导航到第 100 行的唯一方法 -您需要抑制 END-DOWN (2 个键组合...您需要缓冲 END 并询问下一个键:您是 DOWN 吗...玩得开心!)
  • 并且您正在浪费磁盘空间只为第 500 行存储一张包含如此多空白行的工作表

您可能有理由实施按键抑制器,但请始终记住,用户有许多不同的方法可以绕过它,这需要非常仔细地考虑。

The specific answer to your question of course is: trap the usage of the Ctrl-END key.

You can do this easily by specifying the following event triggers to your sheet:

Private Sub Worksheet_Activate()
    Application.OnKey "^{END}", "SuppressMe"
End Sub

Private Sub Worksheet_Deactivate()
    Application.OnKey "^{END}", ""
End Sub

and another module containing

Sub SuppressMe()
    ' you can be very creative here about line 100 or not 100
    MsgBox "Co-Cooooo :-P"
End Sub

Another cute way meeting the requirements you described and eliminating the need of watching and suppressing keys would be to limit navigation to row 100. Now a Ctrl-END would place the user into the rightmost column of row 100, and Ctrl-DOWN would be covered as well. In fact the user just can't go past row 100

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Row > 100 Then
        Me.Cells(100, Target.Column).Select
    End If
End Sub

but .... wait !!! is there really no way? ... of course the user still may SCROLL past row 100 and detect your little row-500 easter egg. So I concur to 100% with earlier suggestions about a different strategy, because

  • a user finding out that exactly line 500 - 503 is hidden can become tremendeously curious about the why's
  • Ctrl-END is not the only way the user can navigate past row 100 - you would need to suppress END-DOWN (a 2 - key combination ... you need to buffer the END and ask the next key: are you a DOWN ... have fun!)
  • and you are wasting disk space to store a sheet with so many blank rows just for that line 500

You may have reasons to implement a key supressor, but always remember there are many different ways for the user to bypass it and this needs to be considered very carefully.

情感失落者 2024-12-10 08:27:20

这是 Excel 的内置行为,我认为您无法更改它。建议:

  • 将隐藏数据放在同一工作簿的另一张工作表上。这确实是最干净的工作方式。
  • 或者,使用Ctrl向下箭头End向下箭头而不是Ctrl< kbd>结束。

That's Excel's built-in behaviour, and I don't think you can change it. Suggestions:

  • Put your hidden data on another sheet of the same workbook. This is really the cleanest way to work.
  • Alternatively, navigate using CtrlDown arrow or EndDown arrow instead of CtrlEnd.
花开雨落又逢春i 2024-12-10 08:27:20

正如其他人所说,将非用户数据分隔在不同的工作表上当然更好。

也就是说,您可以做的一件事是保护您的工作表并禁止访问锁定的单元格,只保留用户必须在其中输入解锁内容的单元格。

这样做可以防止 CtrlEnd 执行任何操作:它无法跳转到最后一个单元格,因为它被锁定,因此它不会执行任何操作。 (在 Excel 2007 上测试)

但是,将用户数据和非用户数据分离到不同的工作表中可能会更好。

As others said it's certainly better to separate your non-user data on a different sheet.

That said, one thing you could do is protect your sheet and disallow access to locked cells, leaving only the cells in which the user has to input something unlocked.

Doing that prevents CtrlEnd from doing anything at all: it can't jump to the last cell as it is locked, so it doesn't do anything. (Tested on Excel 2007)

But again, you'll probably be better off by separating user and non-user data in different sheets.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文