I have a customer who wants me to take a scale and send the weight information to an excel sheet along with the date and time of each weight sample. I have connected it and it works great, for testing I made a command click button on an excel sheet that I would click to run the code. The scale sends 14 cells of information to me along with the actual weight being displayed on the screen. My problem is my code works perfect as long as I'm clicking the button to run the code. I worte a code to monitor a cell for changing from "False" to "True" which the scale changes this information when the weight is correct cell D13 will change from False to True. The data is being exchanged via DDE and excel, the weight is enterned in the next empty cell along with the time and date in the next column is the time and date stamp.
Code below
Private Sub CommandButton1_Click()
Dim mycell As Range
Sheets("Sheet1").Select
Range("G13").Select
If [G13].Value = "True" Then
Range("A1").Select
If [A1] > 0.5 Then
'MsgBox (" This Is Working ")
Dim i As Long
Sheet1.Range("A1").Copy
'For i = 20 To 31 Step 1 '12 places for first paste values
Debug.Print i
If IsEmpty(Range("A1").Value) Then
Else
Range("A" & Range("A:A").Rows.Count).End(xlUp).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheet1.Range("B1").Copy
Debug.Print f
If IsEmpty(Range("B1").Value) Then
Else
Range("B" & Range("B:B").Rows.Count).End(xlUp).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End If
End If
End If
End If
End Sub
After I wrote the code if the cell value changes to run my code, I tested it by using an empty cell first and just throwing up a message box if the value changes to prompt me with a message. The problem is when the cell value changes via DDE my Macro does not see the change because the enter key hasnt been pressed.
Code below
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address = "$D$13" Then
MsgBox "woohooo" ' above code was inserted here, and it did not work.
End If
End Sub
If I use the above worksheet change and I enter a value on the keyboard and press enter it works. But, they want an operator weighing parts and the macro to run when the correct weight is true, not by someone pressing enter every time. Any one have any thoughts??
I would like the macro to run when the DDE changes cells G13 to True one time and then wait until it goes false and true again before it runs again. I have attaced the sheet I have been working on. Thanks for any help. You can email attachments directly to me at billf@clarkpulley.com
File attachment info
Hardy Test.xls - works perfect as long as G13 = "True" and the Start Slug Recorder is clicked.
Hardy Test 1.xls - This is the file I'm trying to get when the DDE changes cell G13 from "False" to "True" to run the code for "Start Slug Recorder"
Thanks
Bookmarks