+ Reply to Thread
Results 1 to 4 of 4

Worksheet Change Macro with multiple Keycell ranges

  1. #1
    Registered User
    Join Date
    07-23-2012
    Location
    uk
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    6

    Worksheet Change Macro with multiple Keycell ranges

    Hi, I’m trying to make the most recent input change made to cells in a series of ranges automatically be copied and pasted elsewhere (which then it turn triggers a vlookup but that bit is fairly irrelevant).

    I’ve managed to create a Worksheet Change macro but I get the “Run-time error ‘1004’: Method ‘Range’ of object ’_Worksheet’ failed” whenever I input one of the cells in the ranges.
    It works fine if I only have 20 ranges rather than the 40 I’ve got in my coding(why is this?! – v frustrating!.
    To get round this I’ve tried (unsuccessfully) experimenting with MultipleRanges and Union. The coding is below, please help. Cheers.

    Please Login or Register  to view this content.
    Last edited by Leith Ross; 07-23-2012 at 01:12 PM. Reason: Added Code Tags

  2. #2
    Forum Contributor wallyeye's Avatar
    Join Date
    05-06-2011
    Location
    Arizona
    MS-Off Ver
    Office 2010, 2007
    Posts
    308

    Re: Worksheet Change Macro with multiple Keycell ranges

    A limitation of the Range property, you can only have 256 characters. You can split it up into multiple groups:

    Please Login or Register  to view this content.
    I cut out some of the intermediate code as well, since you are pastingspecial to get target.value I just directly assigned target.value to range("x508").

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Worksheet Change Macro with multiple Keycell ranges

    Hello owstie ,

    Welcome to the Forum!

    Using the Union method works for combining the ranges. In your macro I disable and enable the Application Events. This is important whenever you aare using Worksheet_Change or Worksheet_SelectionChange events. If you change or select a cell in theses events respectively then you will create a cascade event condition which will cause the stack to overflow. This will usually crash Excel.

    It is rare in VBA that you will need to Select and object before performing an operation on it. Also, if you want to "copy" values, the easiest method is to assign the Value of source range to the destination range.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Registered User
    Join Date
    07-23-2012
    Location
    uk
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    6

    Re: Worksheet Change Macro with multiple Keycell ranges

    Thank you very much gents. Superb help. Looking forward to being part of this forum.

+ 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