Auto Print after scanning in 7 digit barcode

antoniolouis360

New Member
Joined
Oct 13, 2019
Messages
3
Hey guys,
I am wanting to print a label automatically after user scans in barcode in A1. The code I am using is
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
If Intersect(Target, Sheets("Sheet2").Range("A1")) Is Nothing Then Exit Sub
Else
Application.EnableEvents = False
If Len(Target.Value) = 7 Then
ActiveWorkbook.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
Target.ClearContents
Else
End If
End If
Application.EnableEvents = True[/FONT]

This is not working for me and keeps erroring out. Any help would be appreciated.
 

Some videos you may like

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Logit

Well-known Member
Joined
Aug 31, 2016
Messages
3,230
.
I am presuming your macro errors out on the line noted below ?


Code:
If Intersect(Target, Sheets("Sheet2").Range("A1")) Is Nothing Then 
	Exit Sub
Else					'<-- possibly here ?
Application.EnableEvents = False


If Len(Target.Value) = 7 Then
	
Else
	End If				'<--- definitely here
End If


Application.EnableEvents = True




Edit the macro to :


If Intersect(Target, Sheets("Sheet2").Range("A1")) Is Nothing Then Exit Sub


					
Application.EnableEvents = False


If Len(Target.Value) = 7 Then
	ActiveWorkbook.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
	Target.ClearContents
Else
	Exit Sub			'<--- can probably get rid of the Else / Exit Sub and just leave the End If
End If


Application.EnableEvents = True
If that doesn't work let us know.
 

antoniolouis360

New Member
Joined
Oct 13, 2019
Messages
3
.
I am presuming your macro errors out on the line noted below ?


Code:
If Intersect(Target, Sheets("Sheet2").Range("A1")) Is Nothing Then 
	Exit Sub
Else					'<-- possibly here ?
Application.EnableEvents = False


If Len(Target.Value) = 7 Then
	
Else
	End If				'<--- definitely here
End If


Application.EnableEvents = True




Edit the macro to :


If Intersect(Target, Sheets("Sheet2").Range("A1")) Is Nothing Then Exit Sub


					
Application.EnableEvents = False


If Len(Target.Value) = 7 Then
	ActiveWorkbook.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
	Target.ClearContents
Else
	Exit Sub			'<--- can probably get rid of the Else / Exit Sub and just leave the End If
End If


Application.EnableEvents = True
If that doesn't work let us know.
It errors out on:
If Intersect(Target, Sheets("Sheet2").Range("A1")) Is Nothing Then
For both possible solutions
 

Logit

Well-known Member
Joined
Aug 31, 2016
Messages
3,230
Is Sheet 2 the active sheet when you run the macro ?

You can only use Intersect() if the range is on the same worksheet.

Code:
[/FONT][/COLOR]If Intersect(Target, Range("A1")) Is Nothing Then Exit Sub[COLOR=#242729][FONT=Arial]

 

antoniolouis360

New Member
Joined
Oct 13, 2019
Messages
3
Is Sheet 2 the active sheet when you run the macro ?

You can only use Intersect() if the range is on the same worksheet.

Code:
[/FONT][/COLOR]If Intersect(Target, Range("A1")) Is Nothing Then Exit Sub[COLOR=#242729][FONT=Arial]

Yes, sheet 2 is the worksheet. Do I need to specify the title of sheet 2 (Label Printing)?
 

Logit

Well-known Member
Joined
Aug 31, 2016
Messages
3,230
The line in Post #4 should be sufficient.

Side comment: Quoting previous posts in your reply is not required unless it is absolutely necessary to explain your answer.
All the extra data consume extra server space.
 

Watch MrExcel Video

Forum statistics

Threads
1,099,029
Messages
5,466,116
Members
406,468
Latest member
Toto Li

This Week's Hot Topics

Top