Reading QR codes in excel

dominko

New Member
Joined
Jul 13, 2023
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
hello,

I have a problem with scanning QR codes, tried everything but everytime I scan with a 2D barcode scanner it scans the whole number from QR code, all I need is the last 4 numbers from it. The serial number. pls if you have any formulas or anything
Already tried =RIGHT(C14;4), but i need it in the same string as it is scanned so it needs to be replaced in only one line.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Welcome to the Board!

One way to handle this may be with VBA code that runs automatically as a value is entered in a cell in column C.
Try the following code and see if it does what you want.

To ensure it is put in the proper place (so that it runs automatically), do the following:
1. Go to the sheet you wish to apply this to
2. Right-click on the sheet tab name at the bottom of the screen
3. Select "View Code"
4. Paste the following VBA code in the VB Editor window that pops up
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'   Exit if more than one cell updated at once
    If Target.CountLarge > 1 Then Exit Sub
    
'   Only run only column C, on row 2 or below
    If Target.Column = 3 And Target.Row >= 2 Then
'       Trim entry to last four characters
        If Len(Target) > 4 Then
            Application.EnableEvents = False
            Target = Right(Target, 4)
            Application.EnableEvents = True
        End If
    End If

End Sub
5. Save and exit the VB Editor

Try it out and see if it works.
 
Upvote 1
Solution
thanks for your reply, but what should i do next? I did everything you wrote, but I think its not working
 
Upvote 0
Just to test it out and confirm that the code is active, go into any blank cell in column C (other than row 1), and enter in a string that is more than 4 characters long.
If you do that and the code is working, Excel should automatically update your value in that cell to just show the last 4 characters of the entry you just made.
Does that happen?

If so, when you scan the QR code, are the values going in column C, or somewhere else?
I have not worked with QR code scanners before, so maybe it does not work the way I think it does.

Is there VBA code that directs the scans to column C?
If so, can you please post that VBA code, as we may be able to edit that directly?
 
Upvote 0
You are welcome.

I see you marked my post as the solution.
Does that mean it is working now?
If so, what was the issue of why it wasn't working initially?
 
Upvote 0
Will this VBA also work for LibreOffice calc. Thanks for answers.
 
Upvote 0

Forum statistics

Threads
1,215,094
Messages
6,123,071
Members
449,092
Latest member
ipruravindra

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