最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

excel - how to make a macro to stop and then run a code - Stack Overflow

programmeradmin1浏览0评论

I have a code that automatically timestamps on "A" when there's data on the next cells, and delete the date on "A" if I delete the entries, but sometimes I need to do correct previous dates and do manual entries, so I need to stop this code. I need a command button or macro to pause this code and when pressing again, run it again

Private Sub Worksheet_Change(ByVal Target As Range)

  Const ColumnsToMonitor As String = "b:f"    
  Const DateColumn As String = "a"    
  Application.EnableEvents = False
  
   If Not Intersect(Target, Columns(ColumnsToMonitor)) Is Nothing Then

    With Intersect(Target.EntireRow, Columns(DateColumn))
            .Value = Date
            .NumberFormat = "ddd d/mm"
    End With

   End If
  
  On Error Resume Next
  
  If Target = "" Then
  Intersect(Target.EntireRow, Columns(DateColumn)).ClearContents    
  End If
      
  Application.EnableEvents = True

End Sub
发布评论

评论列表(0)

  1. 暂无评论