+ Reply to Thread
Results 1 to 11 of 11

Incrementing occurrences while keeping first instance of barcode

  1. #1
    Forum Contributor
    Join Date
    11-06-2021
    Location
    Tripoli
    MS-Off Ver
    Still using 2007 in 2023
    Posts
    289

    Red face Incrementing occurrences while keeping first instance of barcode

    Hello everyone, I hope you're doing well. I have a question regarding our simple barcode tracking system in Excel.

    I have a list of barcodes in column A that need to be entered manually, and column B would track the number of occurrences of all barcodes entered in column A.
    When a barcode is first entered in column A, I want to register it along with the number "1" in column B. However, if the same barcode is re-entered in column A, I want to prevent Excel from writing it again in column A. Instead, I want to keep the first instance of barcode in column A and to increment its corresponding cell in column B by 1 for every subsequent occurrence of the same barcode.
    For example, based on the excel sheet provided, when "11112" appears for the first time in column A, it should be registered in column A along with the number "1" in column B. If "11112" appears again in a different row in column A, Excel should restrict writing this barcode again in column A and only to add "2" next to "11112" in the first row. The row where the barcode is re-entered should be left blank automatically.

    How can I achieve this using Excel formulas or VBA code?

    Thanks for taking care of my enquiry..
    Attached Files Attached Files

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,417

    Re: Incrementing occurrences while keeping first instance of barcode

    It cannot be done with formulae: if you prevented the bar code entry using data validation, then there would be no way of a formula knowing that anyone had tried to reenter it. It will have to be VBA.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,332

    Re: Incrementing occurrences while keeping first instance of barcode

    Please Login or Register  to view this content.
    Code in Sheet1 (Right click on tab>>view code)
    Attached Files Attached Files
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  4. #4
    Forum Contributor
    Join Date
    11-06-2021
    Location
    Tripoli
    MS-Off Ver
    Still using 2007 in 2023
    Posts
    289

    Re: Incrementing occurrences while keeping first instance of barcode

    The current implementation generates blank cells as intended, but when I hit Enter, the active cell moves to the next one.
    What I'm aiming for is to have the blank cell stay in place after pressing Enter. This would significantly streamline my workflow.
    Thanks for taking care of this..

  5. #5
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,481

    Re: Incrementing occurrences while keeping first instance of barcode

    Try this:
    PHP Code: 
    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim frng As Range
    If Intersect(TargetRange("A3:A100")) Is Nothing Or Target.Count 1 Then Exit Sub
    Set rng 
    Range("A2"Target.Offset(-1))
    Set f rng.Find(Target)
    Application.EnableEvents False
    If Not f Is Nothing Then
        f
    .Offset(01).Value f.Offset(01).Value 1
        Target
    .Value ""
        
    Target.Select
    Else
        
    Target.Offset(01).Value 1
    End 
    If
    Application.EnableEvents True
    End Sub 
    Quang PT

  6. #6
    Forum Contributor
    Join Date
    11-06-2021
    Location
    Tripoli
    MS-Off Ver
    Still using 2007 in 2023
    Posts
    289

    Re: Incrementing occurrences while keeping first instance of barcode

    Hey dear "bebo021999" ...this solved my case, but when a new barcode is entered, the next active cell, shall move downward by one cell, and not to move to the right, as in your case..Thanks a lot for taking care of this..

  7. #7
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,332

    Re: Incrementing occurrences while keeping first instance of barcode

    Please Login or Register  to view this content.

  8. #8
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,481

    Re: Incrementing occurrences while keeping first instance of barcode

    OK. Try again.

    PHP Code: 
    .....................
    Else
        
    Target.Offset(01).Value 1
        Target
    .Offset(10).Select
    End 
    if
    .................... 

  9. #9
    Forum Contributor
    Join Date
    11-06-2021
    Location
    Tripoli
    MS-Off Ver
    Still using 2007 in 2023
    Posts
    289

    Re: Incrementing occurrences while keeping first instance of barcode

    I want to bring up an important matter related to John and Bebo's vba that have been working quite well so far. However, there seems to be an oversight thats pending a correction.
    Currently, their vbas allows for partial barcode matches to be considered valid, which is causing some false positives. For instance, if we enter "7777" or even just "7," it is incorrectly considered to be "7777-01." This is not the behavior we desire, as it may lead to inaccurate results. I appreciate a lot your assistiance to finalize this at your sole convenience.
    Last edited by hasan mougharbel; 07-28-2023 at 07:26 AM.

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,417

    Re: Incrementing occurrences while keeping first instance of barcode

    Whilst I understand that you may be in a bit of a panic, don't tell us that it is urgent, please. All your helpers here are volunteers giving freely of their own time: you haven't paid a penny for any assistance you get here, therefore expecting any form of speed response or preferential treatment, or seeming to, is inappropriate.

    Thank you for your understanding. I have removed the urgency notice from your last post.

    Moderator

  11. #11
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,332

    Re: Incrementing occurrences while keeping first instance of barcode

    Currently, their vbas allows for partial barcode matches to be considered valid, which is causing some false positives. For instance, if we enter "7777" or even just "7," it is incorrectly considered to be "7777-01."
    Not on my testing!!

    I entered "7777-01" and count of 1. Then entered 7777 and count of 1 (new entry)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Removing repeated text across several cells (same column) and keeping first instance
    By adribas in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 11-27-2022, 02:23 AM
  2. Replace Duplicates with Blank Values while Keeping the First Instance
    By JCEurovision in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-17-2022, 10:46 PM
  3. [SOLVED] Remove Duplicate - Specific instance but keeping data from removed instance?
    By NewYears1978 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-22-2022, 12:59 PM
  4. Replies: 2
    Last Post: 04-05-2021, 08:08 PM
  5. Replies: 5
    Last Post: 02-04-2021, 08:18 PM
  6. Replies: 0
    Last Post: 03-17-2017, 10:52 AM
  7. Replies: 1
    Last Post: 12-18-2011, 12:32 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1