创build一个onclick事件来在Excel中附加一个string
我的学校有一个由成绩负责人填写的准时电子表格(excel)。为了确定他们每天迟到的课程数量,他们在单元格中附加了适当数量的X.
这当然需要select单元格,双击,添加X然后移动到下一个学生…通常他们每天可以input超过200个条目,这相当耗时。
我想编写一个点击事件,以便当用户点击(或双击)给定范围内的单元格时,它会自动将X附加到该单元格string。
如果可能的话,一个星期之内这将节省一个荒谬的数额。
我不得不承认,我不知道如何在Excel中启动这个function,尽pipe我能胜任VB.NET和ACCESS的VBA。
我知道这可以用大约1000个macrosbutton来完成,但是必须有更好的方法。
打开VBA编辑器,Alt + F11。
在左侧的窗口中双击您希望使用此function的工作表。
复制粘贴:
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
删除你找不到正确的行。
closuresVBA编辑器并将文件保存为macros启动的Excel文件(xlsm)。
你可以这样做:
打开VBA(Alt + F11)
从左边的窗口打开你想要这个function的工作表。
然后粘贴:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Not Intersect(Target, Range("B5")) Is Nothing Then _ Range("B5") = "X" End Sub
您可以通过更改“B5”来控制范围。 目前只有当您点击B5时才会添加“X”。
最好的方法是使用具有快捷键的macros
Sub AddX()
If ActiveSheet.Name = "Sheet1" Then If ActiveCell.Row > 1 Then Cells(ActiveCell.Row, 2).Value = Cells(ActiveCell.Row, 2).Value & "X" ActiveCell.Offset(1).Select End If End If End Sub