1

我的问题如下:

我正在运行一个实时数据服务器,其倒计时从 900 到 0。一旦倒计时达到 5,我希望 excel 在工作表(RTD_NEWS)中复制范围(B2 到 B61)并将其粘贴到新的工作表中作为值。

问题是当剩余时间达到 5 时,我的宏不会自动执行此操作。如果我在单元格为 5 时点击运行,它会正确运行。

我已经制作了 2 个宏,其中第一个需要按照我的意愿运行,如果我手动更改单元格但不使用 RTD 链接,第二个可以工作。

第一个宏是:

Function Test()
Dim TimeRemaining As Long
TimeRemaining = ActiveWorkbook.Sheets("RTD_NEWS").Range("D2")
If TimeRemaining = 5 Then
Application.Goto ActiveWorkbook.Sheets("RTD_NEWS").Range("B2", "B61")
Selection.Copy
Worksheets.Add
Application.Goto ActiveSheet.Range("B21")
ActiveCell.PasteSpecial (xlPasteValues)
Application.Wait Now + TimeValue("00:00:06")
End If
End Function

第二个宏是:

Sub auto_open()
   ' Run the macro DidCellsChange any time a entry is made in a
   ' cell in Sheet1.
   ThisWorkbook.Worksheets("RTD_NEWS").OnEntry = "DidCellsChange"
End Sub
Sub DidCellsChange()
  Dim KeyCells As String
   ' Define which cells should trigger the KeyCellsChanged macro.
   KeyCells = "D2"
   ' If the Activecell is one of the key cells, call the
   ' KeyCellsChanged macro.
   If Not Application.Intersect(ActiveCell, Range(KeyCells)) _
   Is Nothing Then KeyCellsChanged
End Sub
Sub KeyCellsChanged()
   Dim Cell As Object

    For Each Cell In ActiveWorkbook.Sheets("RTD_NEWS").Range("D2")
   If Cell = "200" Then

Application.Goto ActiveWorkbook.Sheets("RTD_NEWS").Range("B2", "B61")
Selection.Copy
Worksheets.Add
Application.Goto ActiveSheet.Range("B21")
ActiveCell.PasteSpecial (xlPasteValues)
Application.Wait Now + TimeValue("00:00:06")
   End If
   Next Cell
End Sub
4

0 回答 0