如果在设定时间内未完成,如何停止编辑单元格?

时间:2018-03-24 08:18:34

标签: excel vba excel-vba

在我的办公室,我们使用条形码扫描仪计算,但有时用户编辑Excel单元格,手动提供行李编号,所以我想停止手动写入Excel单元格。

该单元格必须仅通过扫描程序进行更新。

我已尝试过以下代码,会返回按键次数,但不会返回时间。

 Private Sub Worksheet_Change(ByVal Target As Range)
    'If Target.Address = Range("A1:A100") Then
    'Enter Code or Call any Function if any process has to be performed
    'When someone Edits the cell A1
    If Range(ActiveCell, ActiveCell.Offset(numRows, numCols)).Offset.Value = "" Then
           Call Demo
    Else: End If
End Sub

Sub Demo()
    'Specify a range (change to suit)
    MsgBox CountKeystrokes(Sheets("Sheet1").Range("A:A"))
    If Range(ActiveCell, ActiveCell.Offset(numRows, numCols)).Offset.Value <> "" Then
        Range(ActiveCell, ActiveCell.Offset(numRows, numCols)).Select
        Selection.ClearContents
    Else
    End If
End Sub

Function CountKeystrokes(rng As Range) As Long
    Dim rCell As Range
    Dim iCtr As Long
    For Each rCell In rng
        iCtr = iCtr + Len(rCell.Formula)
    Next
    CountKeystrokes = iCtr
End Function

0 个答案:

没有答案