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.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
.
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.
 
Upvote 0
.
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
 
Upvote 0
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]


 
Upvote 0
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)?
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,213,535
Messages
6,114,192
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top