+ Reply to Thread
Results 1 to 16 of 16

Range1 = Range2 and Range2 = Range1

  1. #1
    Registered User
    Join Date
    10-04-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    19

    Range1 = Range2 and Range2 = Range1

    Hi,

    I have two ranges of equal size which both have the same data validation applied to them. The data validation applied is a list of R,A,G,N/A.

    I would like to know if there is any coding available that would allow any cell in range1 equal the corresponding cell in range2 (i.e if the ranges are in A1:A4 and B1:B4 then A1 = B1, A2 = B2 etc..) but also so if i change the value in range2, it will also change the value in range1.

    I have seen an example on this forum of how to do this with individual cells but none for named ranges. Might not be looking hard enough!

    Many thanks if anyone can help.

  2. #2
    Forum Contributor Legend Rubber's Avatar
    Join Date
    09-21-2012
    Location
    Tillsonburg, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    392

    Re: Range1 = Range2 and Range2 = Range1

    that would be a circular reference, and i dont think it is really possible without a teritary reprisentative...

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Range1 = Range2 and Range2 = Range1

    Hi, rawcode,

    are you using a List for Data/Validation or do you feed the values directly?

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Registered User
    Join Date
    10-04-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Range1 = Range2 and Range2 = Range1

    I'm awre of circular references but thought this might be possible with some cleverly worded case or if statements. I see the tertiary representitive here being the validation list as that is the item that the other two ranges have in common.

    Below is a link to the post where it has been solved for individual cells:

    http://www.excelforum.com/excel-gene...ll2-cell1.html

    I just cant seem to map this solution over to an entire range.

  5. #5
    Registered User
    Join Date
    10-04-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Range1 = Range2 and Range2 = Range1

    Hi Holgar,

    I am using a list for data/validation here because i thought it might simplfy things. I am also trying to tackle the problem by declaring cell values of the two main ranges as variants, declaring the three ranges and trying to use if statements through a "for each a in t" fashion. No luck yet though!

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Range1 = Range2 and Range2 = Range1

    Hi, rawcode,

    the very easy way is to check the ranges and copy vice versa, my ranges are named test1 (A1:A4) and test2 (B1:B4) and thus work with the Worksheet_Change-event like
    Please Login or Register  to view this content.
    I guess your data will be different from this very easy setup.

    Ciao,
    Holger

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Range1 = Range2 and Range2 = Range1

    It would be a circular reference to try to do it with formulas, but VBA code can do this effectively. Put this code in the module for the worksheet with the data.

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  8. #8
    Registered User
    Join Date
    10-04-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Range1 = Range2 and Range2 = Range1

    Range1 equal Range2.xls

    Thanks to both of you for the quick responses! I have tried both codes and when I attempt to put my list names into them both codes do not seem to do anything.

    I've attached a spreadsheet with both solutions contained on separate sheets. If you guys could have a look and see what i did wrong then I would really appreciate it!

  9. #9
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Range1 = Range2 and Range2 = Range1

    Hi, rawcode,

    Worksheet_Change, not Worksheet_SelectionChange.
    Please Login or Register  to view this content.
    Ciao,
    Holger

  10. #10
    Registered User
    Join Date
    10-04-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Range1 = Range2 and Range2 = Range1

    Haha! Got it to work now! Thanks Holgar, very much appreciated!

    Getting better all the time with tips like these, Thanks to you both.

  11. #11
    Registered User
    Join Date
    10-04-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Range1 = Range2 and Range2 = Range1

    I forgot to ask another quick thing! What if the ranges are arranged in the same column one below another? Would that have a significant impact on the code at all?

  12. #12
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Range1 = Range2 and Range2 = Range1

    Hi, rawcode,

    in that case I悲 recommend to use 6SJ愀 code which would cover that.

    Ciao,
    Holger

  13. #13
    Registered User
    Join Date
    10-04-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Range1 = Range2 and Range2 = Range1

    Ok then, I'll give it a go but still having trouble with encorporating my range names into the code.

    I've also noticed that C has been declared as a range but not set to anything or included in the code. Does the term c need to be set to anything after it has been declared?

    This is 6SJ's code modified. Have i written anything incorrect here?

    Please Login or Register  to view this content.
    Last edited by rawcode; 12-07-2012 at 11:46 AM.

  14. #14
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Range1 = Range2 and Range2 = Range1

    The variable c is there because I originally intended to use it, did not, then forgot to delete it.

    Your changes look correct. What trouble are you having? I have attached my test case [keep two ranges in sync.xlsm] which has modified code to match yours, and it works fine. It does not use data validation, but that doesn't matter long as you don't try to enter data in one cell that would be invalid in it's corresponding cell in the other range.

  15. #15
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Range1 = Range2 and Range2 = Range1

    In your example where you put both solutions in one file, you used the same range names on both sheets. I didn't spend much time to figure it out (because the solution I posted was working) but that may be part of the problem. Here is the solution I posted above, saved for 2003. [keep two ranges in sync.xls]

  16. #16
    Registered User
    Join Date
    10-04-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Range1 = Range2 and Range2 = Range1

    Just tried it out my end and works too. What you said about both sheets using the same named range was probably correct thinking about it, guessing vba got a bit confused that two different codes were being applied to the same named lists!

    As far as I'm concerned this thread is definitely solved for any permutation that I would like to use this code for so thank you very much to the both of you for your time!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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