+ Reply to Thread
Results 1 to 2 of 2

Macro button to collect data from 2 columns of unknown length & duplicates removal

  1. #1
    Registered User
    Join Date
    05-29-2015
    Location
    Germany
    MS-Off Ver
    2010
    Posts
    27

    Macro button to collect data from 2 columns of unknown length & duplicates removal

    Hi, I have two arrays (columns) of lengths j and k, where j, k <= 10,000. I would like to create a macro, which provides me with all unique values from both arrays, i.e. removes duplicates (and blanks).


    Is the following process the best/fastest you can imagine?
    1) Copy values from A1:A10000 into C1:C10000 and B1:B10000 into C10001:C20000*
    2) Remove blanks from C1:C20000*
    3) Remove duplicates from C1:C[latest nonblank row]
    4) Sort C1:C[latest nonblank row] alphabetically
    5) Copy C1:C[latest nonblank row] into D1: (as other functions are based on column D)
    6) Delete/remove whole column C (i.e. column D with values will become C)


    Would it be eventually possible to run steps 1-4 somewhere in the background, so that only "clean values" are being handled with?



    *daffodil11's solution:
    Sub RemoveBlanks()

    For C = 1 To 2
    For R = 1 To 10000
    If Cells(R, C) <> "" Then Cells(R, C).Copy Range("C" & lastrow + 1)
    lastrow = Range("C" & Rows.Count).End(xlUp).Row
    Next
    Next

    End Sub
    Last edited by regresss; 05-29-2015 at 05:23 PM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Macro button to collect data from 2 columns of unknown length & duplicates removal

    Hi,

    VBA macros and certainly any which contain loops will always be slower than a macro that uses standard Excel functionality. The most efficient , quickest and elegant way is to create a single column list as you are doing and then use the Remove duplicates functionality. i.e.

    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

+ 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] Problem Selecting a Range of Cells with Unknown Row Length - Macro
    By ahilty in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-11-2013, 12:41 PM
  2. Data validation with Offset and removal of blanks ?
    By coreytroy in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-14-2007, 10:22 PM
  3. Merge to Columns with Unknown length
    By Steve M in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-06-2006, 02:10 PM
  4. [SOLVED] How do I sum a column of unknown length using a macro
    By SandyPaul in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-26-2005, 05:05 PM
  5. UnKnown Character Removal
    By CyndyG in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-27-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