将excel中的VBA时间戳限制为只有几行

我正在尝试创build一个表来跟踪生产机器的停机时间。 操作员将使用一个表格,列停机时间开始和停止时间。 每当有事情发生,他们不得不离开我想要他们只需要在停机时间统计题目下单击空单元格,时间会出现/日志本身在单元格中,然后停机时间相同。

我有以下代码的作品,如果点击G和H列中的任何地方,当前时间将显示:

Private Sub Worksheet_SelectionChange(ByVal Target As Range) 'Check to see if the click/selected cell is in columns A or B If Not Intersect(Target, Range("G:H")) Is Nothing Then 'Make sure just one cell is selected: If Target.Cells.Count = 1 Then 'Update the value Target.Value = Now() End If End If End Sub 

我该如何做到这一点,只有点击一系列的行才能显示时间? 现在,如果我点击列标题它改变到当前时间,我不想要的。

感谢您的帮助

这个怎么样?

 Private Sub Worksheet_SelectionChange(ByVal Target As Range) 'Check to see if the click/selected cell is in columns A or B If Not Intersect(Target, Range("G:H")) Is Nothing Then 'Make sure just one cell is selected: If Target.Cells.Count = 1 And Target.Row > 1 and Target.Row <= SomeNumber Then 'Update the value Target.Value = Now() End If End If End Sub 

我相信你想要的

 If Target.Row > some number and Target.Row < some other number and (Target.Column = 7 or Target.Column = 8) and Target.Cells.Count = 1 then Target.Value = Now() End If