+ Reply to Thread
Results 1 to 5 of 5

Comparing a range of cells to another range and returning a specific result if match found

  1. #1
    Registered User
    Join Date
    08-21-2012
    Location
    Somerset West, South Africa
    MS-Off Ver
    Excel 2010
    Posts
    16

    Comparing a range of cells to another range and returning a specific result if match found

    Comparing Values Until Matched.xlsmHi. I have a problem constructing vba code that can compare a range of cells (e.g. "A1:F1") in Sheet 2 with a range of cells (e.g. "A1:F49") in Sheet 1. The values in Sheet 1 are changed constantly (using "Calculate") until the values in one of the rows, in the range ("A1:F49"), match those in Sheet 2 ("A1:F1"). When a match is found, the result (i.e. the number of calculations it took to reach that match) must be shown in cell "G1" of Sheet 2.
    If successfull I will then add values in Range ("A2:F2") of Sheet 2 and execute the same code for that range, with the result in cell "G2", and so on,
    Please see attached workbook. Any help will be greatly appreciated.
    Thank you

  2. #2
    Forum Contributor mongoose36's Avatar
    Join Date
    06-10-2013
    Location
    Lincoln
    MS-Off Ver
    Excel 2013
    Posts
    389

    Re: Comparing a range of cells to another range and returning a specific result if match f

    Place this code in a module. When I tested the code the variable "count" 50 which means the code ran through all the rows in Sheet1 and didn't find a match.

    Please Login or Register  to view this content.
    If your questions has been answered to your satisfaction please don't forget to do the following:

    Add Reputation ... and ... Mark Thread as Solved

    Thanks,

    Ma 10:8b Freely you have received; freely give.

  3. #3
    Registered User
    Join Date
    08-21-2012
    Location
    Somerset West, South Africa
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Comparing a range of cells to another range and returning a specific result if match f

    Thanks for the reply. By stepping into the code (F8) I can see that it compares the values in Row 1 of Sheet 2 with the values in each row of Sheet1. However, the values in Sheet 1 of my example are not supposed to be static, they can be "calculated" randomly by pressing and holding the F9 key {using RAND() and RANK functions in HIDDEN columns "I" and "J"}. Sheet 1 has deactivated code attached that, when activated, has to execute a "Do, Calculate Until"-code until the values from any row in Sheet 1 matches the values in row 1 of Sheet 2. So the final code has to "calculate" and compare rows of constantly changing values in Sheet 1 with the values in Row 1 of Sheet 2 until an exact match is made (the values won't necessarily be in the same order as in Sheet 2) and count how many times it "calculated" to reach that match. I hope this explains a bit more of what I'm tryng to achieve.

  4. #4
    Forum Contributor mongoose36's Avatar
    Join Date
    06-10-2013
    Location
    Lincoln
    MS-Off Ver
    Excel 2013
    Posts
    389

    Re: Comparing a range of cells to another range and returning a specific result if match f

    WARNING! This code may run a while. If you want to stop it Ctrl + Pause/Break

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-21-2012
    Location
    Somerset West, South Africa
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Comparing a range of cells to another range and returning a specific result if match f

    Is there perhaps a way to do the calculation while it is comparing, i.e.
    Do Calculate
    For...
    If...
    Else...
    End If...
    Loop Until MatchFound = True? Instead of the code comparing the two ranges, then doing one calculation and again comparing the 2 ranges, then another calculation and comparing, and so on? The idea being that the "Calculation" part mixes the numbers until the rest of the code "catches" the instance where 1 row in range 1 matches range 2. The "Next i" part should be the code moving on to row 2 on sheet 2 where another range of numbers awaits to be compared.

+ 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. Running a WorksheetFunction on a Range of Cells and returning results in 2nd Range
    By excelforum123 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-27-2013, 12:23 PM
  2. [SOLVED] Looking at specific range of numbers and returning the highest found
    By SteinerKD in forum Access Tables & Databases
    Replies: 6
    Last Post: 02-26-2013, 10:10 PM
  3. Replies: 1
    Last Post: 01-23-2013, 01:29 AM
  4. Returning a Certain Result based on a specific data range
    By marktaylor in forum Excel General
    Replies: 3
    Last Post: 11-26-2009, 07:25 AM
  5. Looping through rows in range AND comparing range cells
    By Damask in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-16-2006, 10:30 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