PDA

View Full Version : Scanning Input not considered a Change



ddice
07-29-2019, 08:35 AM
I am using a scanner to input data into an excel spreadsheet. Unfortunately, when I scan in the information, it is not considering it as a "Change" so the macro is not being triggered. The information from the scanner is being inserted into cells in columns A:L. Is there a setting or something I need to change to capture this input as a change?


Private Sub Worksheet_Change(ByVal Target As Range)

Dim myTableRange As Range
Dim myDateTimeRange As Range

Set myTableRange = Range("A1:N20000")
If Intersect(Target, myTableRange) Is Nothing Then Exit Sub
Set myDateTimeRange = Range("P" & Target.Row)
If myDateTimeRange.Value = "" Then
myDateTimeRange.Value = Now
End If

End Sub

NoSparks
07-29-2019, 09:05 AM
Unlike a textbox change event which fires with each key stroke, the worksheet_change event doesn't fire until you exit the cell.

ddice
07-29-2019, 09:46 AM
So I am also using this on for the excel module. It always exits to the next empty cell in column A. The issue I'm running into is if multiple scans come in simultaneously, only the first one writes. With your comment above, I now understand why. Do you see a way to fix that issue?

Sub Save1()
Application.DisplayAlerts = False
ThisWorkbook.Save


'These next 2 columns put the date and time that the record went through in column O

Range("O" & Rows.Count).End(xlUp).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A" & Rows.Count).End(xlUp).Select
ActiveCell.Offset(1, 0).Range("O1").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-14]="""","""",NOW())"
ActiveCell.Offset(1, 0).Range("A1").Select

'These next 2 columns put the time that the record went through in column R
Range("R" & Rows.Count).End(xlUp).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Range("A" & Rows.Count).End(xlUp).Select
ActiveCell.Offset(1, 0).Range("R1").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-17]="""","""",NOW()-TODAY())"
ActiveCell.Offset(1, 0).Range("A1").Select

'These next 2 columns put the time that match the date up with the date that should be in the lot code
Range("S" & Rows.Count).End(xlUp).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Range("A" & Rows.Count).End(xlUp).Select
ActiveCell.Offset(1, 0).Range("S1").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-1]="""","""",IF(RC[-1]<TIME(07,15,00),TODAY()-1,TODAY()))"
ActiveCell.Offset(1, 0).Range("A1").Select


'This is the autosave feature and selects the last first row in column A that doesnt have data
Application.OnTime Now + TimeValue("00:03:01"), "Save1"
Range("A" & Rows.Count).End(xlUp).Select
ActiveCell.Offset(1, 0).Range("A1").Select

'This saves every microsoft excel workbook thats open on the desktop
Dim wb As Workbook
For Each wb In Workbooks
wb.Save
Next wb
End Sub

Artik
07-29-2019, 11:14 AM
Is the suffix surely set in the scanner? This should be a sign Enter or Tab.

Artik