+ Reply to Thread
Results 1 to 10 of 10

Macro to Fire when Range("C1") is modified

  1. #1
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Ventura, united States
    MS-Off Ver
    Excel 2010
    Posts
    346

    Macro to Fire when Range("C1") is modified

    I want to have a macro fire upon a certain event: Range("C3") is changed. How would I program this?

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro to Fire when Range("C1") is modified

    If Target.address=$C3$ then
    '''do something

  3. #3
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    Re: Macro to Fire when Range("C1") is modified

    Need to put AB33's code inside ThisWorkbook and apply it to the Worksheet_Change event

  4. #4
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Ventura, united States
    MS-Off Ver
    Excel 2010
    Posts
    346

    Re: Macro to Fire when Range("C1") is modified

    How do I apply it to worksheet change event?

  5. #5
    Registered User
    Join Date
    02-08-2013
    Location
    Louisiana, USA
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Macro to Fire when Range("C1") is modified

    First you have to put the code listed below in the right place. Make sure you click on the correct VBA project and then click on the 'This Workbook' option. See the file below.

    This Workbook..JPG


    Please Login or Register  to view this content.
    bstier

  6. #6
    Registered User
    Join Date
    01-19-2009
    Location
    UK
    MS-Off Ver
    2007
    Posts
    60

    Re: Macro to Fire when Range("C1") is modified

    Put some code in the Worksheet change event like bstier suggested to catch the change, but since you know the exact cell you can use:

    Please Login or Register  to view this content.
    Also, bstier I think Intersect will return Nothing if there are no intersecting cells so I think you need to check that it's not Nothing, otherwise it will fail:

    Please Login or Register  to view this content.
    Last edited by AKK9; 02-14-2013 at 05:20 PM.
    .
    - AKK9 -

  7. #7
    Registered User
    Join Date
    02-08-2013
    Location
    Louisiana, USA
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Macro to Fire when Range("C1") is modified

    Sorry, The code worked just fine when I changed C3 but when I changed any other cell I would get an error. So here is the corrected code to ignore the change to other cells.

    Please Login or Register  to view this content.

  8. #8
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Macro to Fire when Range("C1") is modified

    Why not use this in the worksheet module?
    Please Login or Register  to view this content.
    When you use the workbook module, you also have to define the sheet it has to apply to.

    For example
    Please Login or Register  to view this content.
    Last edited by Marcol; 02-14-2013 at 06:32 PM.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  9. #9
    Registered User
    Join Date
    02-08-2013
    Location
    Louisiana, USA
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Macro to Fire when Range("C1") is modified

    I got in a hurry before and didn't check to see if the code worked properly when I changed a cell other than C3. When I did this after the post I realized that the code was crashing. Since we don't care about the change of the other cells I used an On Error Goto statement to fix this. AKK9 caught this as well as I did but I have had trouble all afternoon with the Excel Forum site not showing all posts and allowing me to make timely corrections. Thanks for the double check AKK9

    Anyway, this code should be in the Sheet1(Sheet1) and not the ThisWorkbook. Thanks Marcol

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    Re: Macro to Fire when Range("C1") is modified

    Quote Originally Posted by Marcol View Post
    Why not use this in the worksheet module?
    Please Login or Register  to view this content.
    When you use the workbook module, you also have to define the sheet it has to apply to.

    For example
    Please Login or Register  to view this content.
    Thanks for pointing this out, putting it in the Sheet module rather than ThisWorkbook is def. the way to go

+ 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