+ Reply to Thread
Results 1 to 2 of 2

comparing 2 ranges.....problem

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,679

    comparing 2 ranges.....problem

    hi. I am trying to compare 2 ranges using the following code and i can do




    For x = 1 To Currentlist.Count
        For z = 2 To Newlist.Count
        If Workbooks("working_file.xlsm").Worksheets("compare_test").Range("a" & x) = _
                                    Workbooks("working_file.xlsm").Worksheets("compare_test").Range("e" & z) Then matchfound = True
        Next z
        If Not matchfound Then droparray(x) = Workbooks("working_file.xlsm").Worksheets("compare_test").Range("a" & x)
    Next x


    The ranges are currentlist and newlist. the problem is i have to use "workbooks........................" to actually reference each individual component of the range (see above). Is there another way?
    Last edited by welchs101; 12-29-2008 at 12:59 PM.

  2. #2
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,679

    i think i figured it out finally

    to access individual elements in a range you use the ".cells"

    array_cntr = 1
    For x = 1 To Currentlist.Count
        cntr = 1
        mtch = False
        Do
            If Currentlist.Cells(x, 1) = Newlist.Cells(cntr, 1) Then
                mtch = True
            Else: cntr = cntr + 1
            End If
            If mtch Or (cntr > Newlist.Count) Then Exit Do
        Loop
        If Not mtch Then
        ReDim Preserve droparray(array_cntr)
        droparray(array_cntr) = Currentlist.Cells(x, 1)
        array_cntr = array_cntr + 1
        End If
    Next x

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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