Hello Everyone,
I'm new to VBA macros and need some help.
I have "Live Data" through a OPC/DDE link populating in Cell A10. (connected to a PLC through RSLinx)
This data is "dynamic" and updates/changes periodically.
I'm copying the data from A10 and pasting it into C10 (pasted data is pasted as a "static number"
Ten seconds later it pastes the updated data from A10 into C11 and so on...
when pasting into C22, the data in column C clears and pastes once more into C10.
"trending data from C10-C21 for a chart" (dashboard).
Everything works in this code except that when C22 triggers the clear contents funtion
my code errors.
code:
The text in BOLD highlights yellow when i click debug..
any help will be much appreciated.
I'm new to VBA macros and need some help.
I have "Live Data" through a OPC/DDE link populating in Cell A10. (connected to a PLC through RSLinx)
This data is "dynamic" and updates/changes periodically.
I'm copying the data from A10 and pasting it into C10 (pasted data is pasted as a "static number"
Ten seconds later it pastes the updated data from A10 into C11 and so on...
when pasting into C22, the data in column C clears and pastes once more into C10.
"trending data from C10-C21 for a chart" (dashboard).
Everything works in this code except that when C22 triggers the clear contents funtion
my code errors.
code:
Code:
Dim TimeToRun
Sub auto_open()
Call Movedata
End Sub
Sub Movedata()
TimeToRun = Now + TimeValue("00:00:10")
Application.OnTime TimeToRun, "Data"
End Sub
Sub Data()
Dim last As Long
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
last = Application.WorksheetFunction.Max(10, Cells(Application.Rows.Count, "C").End(xlUp).Row + 1)
If last <= 21 Then
Range("A10").Copy
Range("C" & last).PasteSpecial xlPasteValues
Else
Range("C10:C22").ClearContents
Range("A10").Copy
[B] Range("C10" & last).PasteSpecial xlPasteValues[/B]
End If
Application.CutCopyMode = xlCut
Range("A10").Select
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Call Movedata
End Sub
Sub auto_close()
On Error Resume Next
Application.OnTime TimeToRun, "Data", , False
End Sub
The text in BOLD highlights yellow when i click debug..
any help will be much appreciated.