创建onclick事件以在Excel中追加字符串(Creating an onclick event to append a string in Excel)

编程入门 行业动态 更新时间:2024-10-25 16:22:12
创建onclick事件以在Excel中追加字符串(Creating an onclick event to append a string in Excel)

我的学校有一个准时电子表格(excel),由成就负责人填写。为了确定他们每天晚上有多少课程,他们将适当数量的X附加到单元格。

这当然需要选择单元格,双击,添加X然后移动到下一个学生...通常他们每天可以输入200多个条目,这是相当耗时的。

我想编写一个点击事件,以便当用户点击(或双击)给定范围内的单元格时,它会自动将X附加到该单元格字符串。

如果可能的话,如果时间过了一个星期,这将节省一笔可笑的金额。

我不得不承认我不确定如何在Excel中启动它,尽管我能胜任VB.NET和VBA for ACCESS。

我知道这可以用大约1000个宏按钮完成,但必须有更好的方法。

My school has a punctuality spreadsheet (excel) which is filled in by the head of achievement.To identify how many lessons they have been late each day they append the appropriate number of X's to the cell.

This of course requires selecting the cell, double clicking, adding the X then moving onto the next of student... typically they can enter over 200 entries a day which is rather time consuming.

I'd like to write an on-click event so that when the user clicks (or double clicks) a cell in a given range it automatically appends an X to that cells string.

Over a week this will save a ridiculous amount if time if it is possible.

I have to admit I'm not certain how to start this in Excel, though I am competent with VB.NET and VBA for ACCESS.

I know this could be accomplished with around 1000 macro buttons but there must be a better way.

最满意答案

打开VBA编辑器,Alt + F11。

在左侧窗口中双击要使用此功能的工作表。

复制粘贴:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) Target.Value = "x" ' if you want to replace the value in the cell with x Target.value = Target.Value & "x" ' if you want to add one x to the value of the cell End Sub

删除找不到符合您需求的行。

关闭VBA编辑器并将文件另存为宏激活的excel文件(xlsm)。

Open VBA editor, Alt + F11.

Doubleclick on the sheet you want this function on in the window to the left.

Copy paste:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) Target.Value = "x" ' if you want to replace the value in the cell with x Target.value = Target.Value & "x" ' if you want to add one x to the value of the cell End Sub

Delete the row you do not find correct for your needs.

Close VBA editor and save file as macroactivated excel file (xlsm).

更多推荐

本文发布于:2023-07-27 15:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1292397.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   事件   Excel   onclick   string

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!