+ Reply to Thread
Results 1 to 26 of 26

Macro to count duplicates then number them in a separate column

  1. #1
    Registered User
    Join Date
    05-27-2015
    Location
    london
    MS-Off Ver
    2003
    Posts
    22

    Macro to count duplicates then number them in a separate column

    Hi,

    I love excell but am struggling with a macro. I hope someone can help.

    I am trying to create a macro that will take the values of columnB, count the duplicates then display the values in columnE with the total number of value duplicates in ColumnF


    I sourced this code which does something like I want but I cant split the Value B data(Code is A) into separate columns. I might be over thinking it. Code below.


    Please Login or Register  to view this content.
    Last edited by paperbo; 01-11-2018 at 12:15 PM. Reason: Request to comply with rules

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Macro to count duplicates then number them in a separate column

    Important
    - please click on edit post on your post and add code tags to your code by selecting the relevant text and then clicking on #
    - this makes the code easier to read and complies with forum rules

    What goes in column E? - is it the duplicate value?
    What goes in F? - I am not sure what you are trying to split
    What is in B?

    Perhaps you could attach a workbook showing the original values and what you want in D & E
    - click GoAdvanced
    - look below and click on ManageAttachments
    - follow screen instructions
    Thanks
    Last edited by kev_; 01-11-2018 at 11:09 AM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Registered User
    Join Date
    05-27-2015
    Location
    london
    MS-Off Ver
    2003
    Posts
    22

    Re: Macro to count duplicates then number them in a separate column

    Hi,

    Thanks for getting back to me so quickly. I hope this attached image explains it a bit better.
    The image is how i want it to display after the macro is run.

    Untitled.jpg

  4. #4
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Macro to count duplicates then number them in a separate column

    - range of values is attributed to column E, then sorted and duplicates removed
    - column E contains result of CountIf function
    - headers added

    - run in attached workbook with {CTRL} k

    Please Login or Register  to view this content.
    Plesae add code tags to post#1 as requested in post#2


    paperbo.xlsm
    Last edited by kev_; 01-11-2018 at 11:50 AM.

  5. #5
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Macro to count duplicates then number them in a separate column

    You could also achieve this without VBA

    In E4 copy down
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    In F4 copy down
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    The 2nd formula lazily refers to whole of column B
    - should be OK unless area above/below data in column B contains value matching a Barcode
    Last edited by kev_; 01-11-2018 at 11:52 AM.

  6. #6
    Registered User
    Join Date
    05-27-2015
    Location
    london
    MS-Off Ver
    2003
    Posts
    22

    Re: Macro to count duplicates then number them in a separate column

    This sort of works but it generates an error.
    please see image attached.

    Untitled2.jpg

  7. #7
    Registered User
    Join Date
    05-27-2015
    Location
    london
    MS-Off Ver
    2003
    Posts
    22

    Re: Macro to count duplicates then number them in a separate column

    Hi,

    This also partially works and may be a way forward. Clearing the blank cells with a macro removes the formula thought. The data from column E and F will be copied and pasted into another spreadsheet which can sort everything out using concatenation. I just want to tidy it up a bit before i copy and paste.

  8. #8
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Macro to count duplicates then number them in a separate column

    The VBA error is probably due to the your Excel version
    - are you running Excel 2003?
    - the remove duplicates function was probably introduced with Excel 2007
    - let me know and I will revise the VBA tomorrow

  9. #9
    Registered User
    Join Date
    05-27-2015
    Location
    london
    MS-Off Ver
    2003
    Posts
    22
    Quote Originally Posted by kev_ View Post
    The VBA error is probably due to the your Excel version
    - are you running Excel 2003?
    - the remove duplicates function was probably introduced with Excel 2007
    - let me know and I will revise the VBA tomorrow
    Hi,

    Yes, I’m on Excel 2003. It’s a massive help this, that will be used on a daily basis for my stock control system.

  10. #10
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Macro to count duplicates then number them in a separate column

    - I think this should work with Excel 2003
    - Barcode count values placed in a new worksheet named "Unique"
    - making it easy to delete that worksheet if you then copy them elsewhere
    - run in attached workbook with {CTRL} k

    How it works:
    - sheet containing barcodes activated to set the correct range of values to use
    - new worksheet added
    - barcode values attributed to new sheet (more efficient than copy/paste) starting at A2
    - new values sorted
    - TWO counts calculated for each barcode (total and cumulative to each row)
    - total count placed in columnB (BUT only against first occurence of barcode - ie when cumulative count = 1)
    - rows where cell in columnB is BLANK deleted (identified using SpecialCells property)

    Any questions?
    - you must ask if there is anything in the code that you do not fully understand
    - if you need further help in taking things to the next stage let me know

    Please Login or Register  to view this content.
    paperbo v2.xlsm

  11. #11
    Registered User
    Join Date
    05-27-2015
    Location
    london
    MS-Off Ver
    2003
    Posts
    22

    Re: Macro to count duplicates then number them in a separate column

    Quote Originally Posted by kev_ View Post
    - I think this should work with Excel 2003
    - Barcode count values placed in a new worksheet named "Unique"
    - making it easy to delete that worksheet if you then copy them elsewhere
    - run in attached workbook with {CTRL} k

    How it works:
    - sheet containing barcodes activated to set the correct range of values to use
    - new worksheet added
    - barcode values attributed to new sheet (more efficient than copy/paste) starting at A2
    - new values sorted
    - TWO counts calculated for each barcode (total and cumulative to each row)
    - total count placed in columnB (BUT only against first occurence of barcode - ie when cumulative count = 1)
    - rows where cell in columnB is BLANK deleted (identified using SpecialCells property)

    Any questions?
    - you must ask if there is anything in the code that you do not fully understand
    - if you need further help in taking things to the next stage let me know

    Please Login or Register  to view this content.
    Attachment 555771

    You Sir, are an absolute genius ! It works perfectly and far better than I could get it. Placing the required output data on a different sheet is perfect although this data needs moving manually to a different workbook which is not a problem. Its in a nice tidy format and will work well once pasted into the correct location. We will be able to start implementing this system next week.

    Just for your information, the document sits in Onedrive and is accessed via a Windows10 notebook. input is via a bluetooth barcode scanner. The data is fed in and then sorted . Once saved the document is then accessed by another computer/person and the output data in 'Unique' pasted into another workbook that controls stock levels. The data is then sorted again and applied via the bar code to the product.

    I cant thank you enough.

    Ray

  12. #12
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Macro to count duplicates then number them in a separate column

    this data needs moving manually to a different workbook
    That process could probably be automated
    How is it incorporated in the other workbook?
    - as a new workbook?
    - into an existing workbook?
    - into a new sheet?
    - into an existing sheet?

    Let me know what you are doing manually, and perhaps we can make ife easier

  13. #13
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Prof Plus 2021
    Posts
    7,018

    Re: Macro to count duplicates then number them in a separate column

    Another one.
    Please Login or Register  to view this content.
    Last edited by bakerman2; 01-12-2018 at 08:10 PM.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  14. #14
    Registered User
    Join Date
    05-27-2015
    Location
    london
    MS-Off Ver
    2003
    Posts
    22

    Re: Macro to count duplicates then number them in a separate column

    Quote Originally Posted by kev_ View Post
    That process could probably be automated
    How is it incorporated in the other workbook?
    - as a new workbook?
    - into an existing workbook?
    - into a new sheet?
    - into an existing sheet?

    Let me know what you are doing manually, and perhaps we can make ife easier
    Hi, I have just run this through a complete cycle: Barcode scanner>notebook>onedrive>copy and paste>final stock, and it works perfectly. The master sheet (it gets pasted into ) is not on onedrive as its a secure excel document. For the record, Column A and B in Unique, are pasted into and existing sheet in an existing workbook.

  15. #15
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Macro to count duplicates then number them in a separate column

    @bakerman2 - nice

    @paperbo
    This overwrites a sheet in other workbook with "Unique"'s values - is that what you want?
    Please Login or Register  to view this content.
    You could create the unique list directly in the other workbook (instead of "Unique")
    - it would be fairly easy to amend the code
    - let me know

  16. #16
    Registered User
    Join Date
    05-27-2015
    Location
    london
    MS-Off Ver
    2003
    Posts
    22

    Re: Macro to count duplicates then number them in a separate column

    Quote Originally Posted by kev_ View Post
    - I think this should work with Excel 2003
    - Barcode count values placed in a new worksheet named "Unique"
    - making it easy to delete that worksheet if you then copy them elsewhere
    - run in attached workbook with {CTRL} k

    How it works:
    - sheet containing barcodes activated to set the correct range of values to use
    - new worksheet added
    - barcode values attributed to new sheet (more efficient than copy/paste) starting at A2
    - new values sorted
    - TWO counts calculated for each barcode (total and cumulative to each row)
    - total count placed in columnB (BUT only against first occurence of barcode - ie when cumulative count = 1)
    - rows where cell in columnB is BLANK deleted (identified using SpecialCells property)

    Any questions?
    - you must ask if there is anything in the code that you do not fully understand
    - if you need further help in taking things to the next stage let me know

    Please Login or Register  to view this content.
    Attachment 555771

    Hi again,

    There is always something that gets thrown into the mix at some point ! I am currently messing about with the interface on the notebook to make it user friendly and it started throwing up an error. I traced it to if there are no duplicates then the macro fails. It is failing at this point.

    Please Login or Register  to view this content.
    It opens up a new workbook sheet called sheet1 then stops. If you start again and add a duplicate then all is well.

  17. #17
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Macro to count duplicates then number them in a separate column

    Try
    Please Login or Register  to view this content.
    SpecialCells fails if no cells found

  18. #18
    Registered User
    Join Date
    05-27-2015
    Location
    london
    MS-Off Ver
    2003
    Posts
    22

    Re: Macro to count duplicates then number them in a separate column

    Hi,

    That works perfectly.

    Many thanks.

  19. #19
    Registered User
    Join Date
    05-27-2015
    Location
    london
    MS-Off Ver
    2003
    Posts
    22

    Re: Macro to count duplicates then number them in a separate column

    Hi,

    All is going well with this project and the advice so far has been excellent. I have uncovered anotther issue however. Part of the sheet contains a Macro that allows the deletion of the last stock itam. This originally worked fine but I have a problem now. See code below

    Please Login or Register  to view this content.
    For one form of stock this works fine as its numerical but if the stock code is prefixed by a letter then it does nothing as the formula contains an IfNumeric statement. I can only see 2 ways of solving this. I cant get IfText to work as the string contains 1 letter then 4 numbers and another letter. It might be possible to get the macro to ignore the first letter and use the second character number but not sure if this is the best solution.

  20. #20
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Macro to count duplicates then number them in a separate column

    What is the purpose of the 3rd line?
    - suggest you delete it
    (doing nothing because you are using variable "i" again on the next line)

    What tests do you want the stock code to pass
    - Is it always alphanumeric?
    - Could it be either alpha or numeric only? etc

    And perhaps more importantly....
    - What types of values could be in the cell when you want it to fail the test?

  21. #21
    Registered User
    Join Date
    05-27-2015
    Location
    london
    MS-Off Ver
    2003
    Posts
    22

    Re: Macro to count duplicates then number them in a separate column

    Hi,

    Sorry, the 3rd line of code shouldn't exist as I was experimenting.


    Please Login or Register  to view this content.
    The deletion of the original numbers (1001,1002,1003 etc...) works fine for that specific worksheet. On another worksheet I am using the same formula but I have codes (R1002, R1023, R1027a etc...). I need to apply a Macro that will recognise the values. Its irrelevant what the values are (mix of letters and numbers). It just needs to acknowledge that there is a value and remove it. It is not conditional as removal is decided by the user. The 1st character is always a letter and the second is always a number.
    Last edited by paperbo; 01-16-2018 at 01:22 PM.

  22. #22
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Macro to count duplicates then number them in a separate column

    I have already replied to this on post#20.

  23. #23
    Registered User
    Join Date
    05-27-2015
    Location
    london
    MS-Off Ver
    2003
    Posts
    22

    Re: Macro to count duplicates then number them in a separate column

    I have edited post #21. not sure how I resent it ??

  24. #24
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Macro to count duplicates then number them in a separate column

    If it needs a value of any kind then try

    Please Login or Register  to view this content.

  25. #25
    Registered User
    Join Date
    05-27-2015
    Location
    london
    MS-Off Ver
    2003
    Posts
    22

    Re: Macro to count duplicates then number them in a separate column

    Quote Originally Posted by kev_ View Post
    If it needs a value of any kind then try

    Please Login or Register  to view this content.
    Had to tweak it a bit but its working fine now and deleting the contents of a cell, irrespective of character type, with a form button. That is now the end of this and i would like to thank you again for your amazing advice.

  26. #26
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Macro to count duplicates then number them in a separate column

    Glad you are sorted
    You can mark the thread as SOLVED by clicking on ThreadTools at top of thread

+ 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] count duplicates in Column E in all worksheets and write their number in Column H
    By wali in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-13-2015, 06:19 AM
  2. Count number of cells associated with value in separate column
    By lamdl in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-13-2014, 03:48 PM
  3. Replies: 2
    Last Post: 09-25-2013, 10:14 AM
  4. [SOLVED] Count Duplicates in Column A once as long as there is a number higher than 0 in Column B
    By armbands1 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-05-2013, 01:46 AM
  5. [SOLVED] Macro to count unique values in a column, enter it in next column, then delete duplicates
    By pmorisse in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-25-2013, 03:27 PM
  6. Count duplicates and put their number in next column
    By wali in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-21-2011, 05:59 PM
  7. [SOLVED] Count number of unique items in a column that contains duplicates
    By Steembeem in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-01-2005, 09:06 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