+ Reply to Thread
Results 1 to 10 of 10

code to detect cell range change

  1. #1
    Registered User
    Join Date
    08-19-2014
    Location
    atlanta, ga, usa
    MS-Off Ver
    2007
    Posts
    9

    code to detect cell range change

    i am trying to have a change in the range of a worksheet to activate a macro that copies, paste and sort the data from that range into another one. the copy/paste/sort macro portion works well but the code to detect the range change and call up the macro doesn't. I'm getting a "run-time 424 error". I ran this once and it worked but hasn't since. I have the following:

    Please Login or Register  to view this content.



    Here's what i've tried:

    loaded ms DAO object library
    used the "Private Sub Worksheet_Change()" event

    Please note the macro to copy/paste/sort is in a module.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: code to detect cell range change

    This is a sheet specific macro that runs whenever your worksheet calculates, normally whenever you make a change.

    You should be use a selection_change event instead.

    The macro will run another macro if you have selected the range O30 to O70.

    Now is that what you wanted?

  3. #3
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: code to detect cell range change

    There is no 'Target' in the worksheet_calculate event. Use the worksheet_change event.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  4. #4
    Registered User
    Join Date
    08-19-2014
    Location
    atlanta, ga, usa
    MS-Off Ver
    2007
    Posts
    9

    Re: code to detect cell range change

    mehmetcik,

    did changing the worksheet event work for you? i tried your suggestion and didn't have any luck.

  5. #5
    Registered User
    Join Date
    08-19-2014
    Location
    atlanta, ga, usa
    MS-Off Ver
    2007
    Posts
    9

    Re: code to detect cell range change

    olly,

    i've tried the "worksheet_change" event before and again recently. i don't get an error msg but the code
    doesn't run the macro. nothing happens. must be a glitch or i'm missing something

  6. #6
    Registered User
    Join Date
    08-15-2014
    Location
    St.Petersburg, Russia
    MS-Off Ver
    MSO Excel 2010
    Posts
    20

    Re: code to detect cell range change

    Rachee, as far as I know, changes made by calculation do not catched by Worksheet_Change event. And as far as Worksheet_Calculate event do not have Target, you can only choose to run your macro on EVERY recalculating, or, if you need to catch changes in determined range, I suppose that global public variable, which filled with values on Workbook_Open and updated after calculation, could help.

  7. #7
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: code to detect cell range change

    Quote Originally Posted by rachee View Post
    olly,

    i've tried the "worksheet_change" event before and again recently. i don't get an error msg but the code
    doesn't run the macro. nothing happens. must be a glitch or i'm missing something

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  8. #8
    Registered User
    Join Date
    08-19-2014
    Location
    atlanta, ga, usa
    MS-Off Ver
    2007
    Posts
    9

    Re: code to detect cell range change

    olly

    this is just an example of what i need to happen
    Attached Files Attached Files

  9. #9
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: code to detect cell range change

    So, based on your example:
    Please Login or Register  to view this content.

  10. #10
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: code to detect cell range change

    Or, to sort the whole range based on changes to Value1 or Value2:
    Please Login or Register  to view this content.

+ 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. code to detect cell range change
    By rachee in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-12-2014, 03:10 PM
  2. Replies: 7
    Last Post: 02-27-2014, 10:56 PM
  3. [SOLVED] Detect when all cells in a range change value
    By ozizushi in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-22-2014, 12:09 PM
  4. VBA code to detect change in cells filled by combo box
    By Jollyfrog in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 02-25-2013, 07:58 AM
  5. VBA Code to detect change in fiscal year between dates
    By miam in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-25-2011, 03:33 AM

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