+ Reply to Thread
Results 1 to 10 of 10

Copy values that appear at least 3 times in a column

  1. #1
    Registered User
    Join Date
    11-27-2014
    Location
    united kingdom
    MS-Off Ver
    2010
    Posts
    5

    Copy values that appear at least 3 times in a column

    Hi, I'm a newbie in Excel. I appreciate any help to create a VBA that Copy values that appear at least 3 times in column A to column B.
    Example:
    Column A
    1
    2
    3
    4
    5
    6
    7
    1
    2
    8
    9
    1
    3
    5
    10
    11
    3
    12
    13
    1
    15

    Column B:
    1
    3
    Green numbers only appear twice so they're not copied to column B.

    Thanks in advance
    Last edited by windblife; 11-28-2014 at 10:07 AM. Reason: solved

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Copy values that appear at least 3 times in a column

    Try

    Please Login or Register  to view this content.
    Attached Files Attached Files
    - Battle without fear gives no glory - Just try

  3. #3
    Registered User
    Join Date
    11-27-2014
    Location
    united kingdom
    MS-Off Ver
    2010
    Posts
    5

    Re: Copy values that appear at least 3 times in a column

    thanks PCI. I tried your code but it says type mismatch. DO I miss anything?
    Y2aFUnF.jpg

  4. #4
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Copy values that appear at least 3 times in a column

    Is it happening with the file I sent you?
    If yes try again the file attached: No big changes but ...
    Else send an update of your file
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    11-27-2014
    Location
    united kingdom
    MS-Off Ver
    2010
    Posts
    5

    Re: Copy values that appear at least 3 times in a column

    It worked with your file.
    If happens on my own sheets. It doesn't work on sheet 2 but ok on sheet 1. I don't know whether macros only work on certain sheets.
    May I ask, if data in column A is already sorted, can you make faster version for both cases: duplicated (appear at least twice) case and appear at least 3 times case? I think it would be a lot faster because duplicated values are next to each others.
    Last edited by windblife; 11-28-2014 at 04:02 AM.

  6. #6
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Copy values that appear at least 3 times in a column

    "It doesn't work on sheet 2 but ok on sheet 1" YES it works with the active sheet, do you want it to works for all sheets?
    Do you want column B for data appearing twice and column C for data appearing times ?

  7. #7
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Copy values that appear at least 3 times in a column

    Here an example to treat data appearing twice and 3 times for tha avtive sheet.
    It should be faster
    Waiting for your informaton concerning sheets to treat: All of them or a limited sheets list (give the name)

    Please Login or Register  to view this content.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    11-27-2014
    Location
    united kingdom
    MS-Off Ver
    2010
    Posts
    5

    Re: Copy values that appear at least 3 times in a column

    I figured out why it only works on certain sheet . Because I put code in VBA on sheet 1 but run macro on sheet 2
    About sorting, I didn't ask to put sorting function on the sheet. I thought that, if data is sorted, there would be another algorithm to select duplicate values much faster. It's like finding number in a sorted list is much faster using binary search, than normal search algorithm in a random list.
    Thanks a lot for your help PCI. My last request: Can you separate your code to 2 sheets, sheet 1 to copy values appear twice, sheet 2 to copy values appear 3 times? Because I don't need to filter both at the same time.
    Last edited by windblife; 11-28-2014 at 09:59 AM.

  9. #9
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Copy values that appear at least 3 times in a column

    OK
    See attached a file with 2 macros:
    Sub Treat2() is preparing the list when there is at least 2 same values in the active sheet
    Sub Treat3() is preparing the list when there is at least 3 same values in the active sheet
    Attached Files Attached Files
    Last edited by PCI; 11-28-2014 at 10:29 AM. Reason: Typo

  10. #10
    Registered User
    Join Date
    11-27-2014
    Location
    united kingdom
    MS-Off Ver
    2010
    Posts
    5

    Re: Copy values that appear at least 3 times in a column

    thanks again bro. Problem totally solved.
    512px-Thumbs_up_font_awesome.svg.png

+ 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. Copy Cell Values in two Columns down x number of times then jump and copy some more.
    By scholly23 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-02-2014, 03:19 AM
  2. [SOLVED] Count values in column, paste current year in another column that many times
    By johnstevens in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-05-2014, 02:32 PM
  3. Replies: 3
    Last Post: 02-19-2014, 10:47 AM
  4. Copy and Paste data in column A number of times displayed in column B
    By anthony232 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-15-2013, 05:13 PM
  5. Copy Selected range values for few times
    By montroseite in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-01-2010, 03:49 AM

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