I'm currently writing or trying to write the code that connects a PLC to a pc and then capture data from the plc to the pc and insert the event in a worksheet on microsoft excel. It's works somewhat but here is my problem, when the cell value of AA10 changes on sheet one (either a 1 or 0 binary), I want the macro to log the time in one column and then display a text message in the next column to that time.
I will have this system connected to a conveyor line to log down time, so when the operator presses the E_Stop button at the first station (6 stations total can stop the line) it will log what time the operator pressed the button which changes the state of AA10 from 1 to 0. Then when the operator releases the stop button the value in cell AA10 changes from 0 to 1. Each time this occurs I'll have a message that shows in the next column which stop was pressed and when it was released.
Here is the code that I'm using now.
Private Sub Worksheet_Calculate()
'Code Below Logs The Stop Time For USDA Station #1 Stop Time.
'
If [AA10] = 0 Then
' Logs The Time That Station 1 Line 1 Stopped The Line
' Determines The Next Empty Row In Column A
Sheets(2).Range("A65536").End(xlUp).Offset(1, 0) = Time
'ActiveCell.NumberFormat = "h:mm:ss AM/PM"
' Logs The Description of The Event Next To The Time
' Determines The Next Empty Row In Column B
Sheets(2).Range("B65536").End(xlUp).Offset(1, 0) = "Station 1 Line 1 Stopped The Line"
End If
' Logs The Time That Station 1 Line 1 Released The Line
If [AA10] = 1 Then
Sheets(2).Range("A65536").End(xlUp).Offset(1, 0) = Time
'ActiveCell.NumberFormat = "h:mm:ss AM/PM"
' Logs The Description of The Event Next To The Time
Sheets(2).Range("B65536").End(xlUp).Offset(1, 0) = "Station 1 Line 1 Released The Line"
End If
End If
End Sub
The problem is when any cell is clicked it changes that cell to the time format that I'm using above. I know why because I'm using the active cell number format. I'm new at all this VBA and I'm not sure how to make that just a selected range not everything that is active.
2nd problem is when I added a another station monitoring another cell plus the one above it would run the entire code in the Private Sub Worksheet_Calculate() area. I just want to log the information if that state changes once from 1 to 0. If any of the other six stations change I don't want to know the status of the ones that are pressed. I just want to log when this ESTOP button is pressed (time hh:mm:ss) and when it was released (time hh:mm:ss). and insert this information in sheet two. When the stop time is inserted in A1 I want a text message inserted in to B1 that says "Station 1 Estop has Been Pressed" or something.
Is there some code that I can write just to watch a single cell then run some event or wait for a event.
Thanks!!!!
I will have this system connected to a conveyor line to log down time, so when the operator presses the E_Stop button at the first station (6 stations total can stop the line) it will log what time the operator pressed the button which changes the state of AA10 from 1 to 0. Then when the operator releases the stop button the value in cell AA10 changes from 0 to 1. Each time this occurs I'll have a message that shows in the next column which stop was pressed and when it was released.
Here is the code that I'm using now.
Private Sub Worksheet_Calculate()
'Code Below Logs The Stop Time For USDA Station #1 Stop Time.
'
If [AA10] = 0 Then
' Logs The Time That Station 1 Line 1 Stopped The Line
' Determines The Next Empty Row In Column A
Sheets(2).Range("A65536").End(xlUp).Offset(1, 0) = Time
'ActiveCell.NumberFormat = "h:mm:ss AM/PM"
' Logs The Description of The Event Next To The Time
' Determines The Next Empty Row In Column B
Sheets(2).Range("B65536").End(xlUp).Offset(1, 0) = "Station 1 Line 1 Stopped The Line"
End If
' Logs The Time That Station 1 Line 1 Released The Line
If [AA10] = 1 Then
Sheets(2).Range("A65536").End(xlUp).Offset(1, 0) = Time
'ActiveCell.NumberFormat = "h:mm:ss AM/PM"
' Logs The Description of The Event Next To The Time
Sheets(2).Range("B65536").End(xlUp).Offset(1, 0) = "Station 1 Line 1 Released The Line"
End If
End If
End Sub
The problem is when any cell is clicked it changes that cell to the time format that I'm using above. I know why because I'm using the active cell number format. I'm new at all this VBA and I'm not sure how to make that just a selected range not everything that is active.
2nd problem is when I added a another station monitoring another cell plus the one above it would run the entire code in the Private Sub Worksheet_Calculate() area. I just want to log the information if that state changes once from 1 to 0. If any of the other six stations change I don't want to know the status of the ones that are pressed. I just want to log when this ESTOP button is pressed (time hh:mm:ss) and when it was released (time hh:mm:ss). and insert this information in sheet two. When the stop time is inserted in A1 I want a text message inserted in to B1 that says "Station 1 Estop has Been Pressed" or something.
Is there some code that I can write just to watch a single cell then run some event or wait for a event.
Thanks!!!!