Barcode Scan; Remove extra characters & add a date and timestamp

sgaller31

New Member
Joined
Jun 24, 2015
Messages
2
Hello,

I'm new to the forum, but I use the site for help all the time. Usually I am able to figure it out based on other issues threads, but this one has me stumped.

I am looking to run two subs, one to remove extra characters on the barcode scan itself (see below for code).

Private Sub Worksheet_Change2(ByVal Target As Range)
If Intersect(Target, Range("A2:A10000")) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
If Target = "" Then Exit Sub
With Application2
.EnableEvents = False
.ScreenUpdating = False
If Left(Target, 1) = "G" Then Target = Left(Target, Len(Target) - 7)
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub

this works fine on its own.

Then I am also looking to add a date and timestamp to the column next to it (see code below)

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A2:A3000")) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
If Target = "" Then Exit Sub
Dim lc As Long
With Application
.EnableEvents = False
.ScreenUpdating = False
lc = Cells(Target.Row, Columns.Count).End(xlToLeft).Column
If lc = 1 Then
Cells(Target.Row, lc + 1) = Format(Now, "m/d/yyyy - h:mm")
ElseIf lc > 2 Then
Cells(Target.Row, lc + 2) = Format(Now, "m/d/yyyy - h:mm")
End If
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub

this also works by itself.

But I haven't been able to find a way to make the two changes together. PLEASE HELP ME!

Thank you,
Steve
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
what about:

Code:
'---------------
Private Sub Worksheet_Change(ByVal Target As Range)
'---------------
  FixBarcode
  FixTime
End Sub

'---------------
Sub FixBarcode()
'---------------
If Intersect(Target, Range("A2:A10000")) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
If Target = "" Then Exit Sub
With Application2
    .EnableEvents = False
    .ScreenUpdating = False
    If Left(Target, 1) = "G" Then Target = Left(Target, Len(Target) - 7)
    .EnableEvents = True
    .ScreenUpdating = True
End With
End Sub
'---------------
Sub FixTime()
'---------------
Dim lc As Long


If Intersect(Target, Range("A2:A3000")) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
If Target = "" Then Exit Sub
With Application
    .EnableEvents = False
    .ScreenUpdating = False
    lc = Cells(Target.Row, Columns.Count).End(xlToLeft).Column
    If lc = 1 Then
       Cells(Target.Row, lc + 1) = Format(Now, "m/d/yyyy - h:mm")
    ElseIf lc > 2 Then
       Cells(Target.Row, lc + 2) = Format(Now, "m/d/yyyy - h:mm")
    End If
    .EnableEvents = True
    .ScreenUpdating = True
End With
End Sub
 
Upvote 0
Thank you for the help, but it unfortunately didn't work. It got hung up on the 'if' statements that are in the new subs. I tried something similar early, trying to create subs in the main body, but every time I step through it stops at the 'if/then' statements before it can even run the main code.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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