+ Reply to Thread
Results 1 to 10 of 10

How to write Worksheet ChangeEvent if cell value is great than one

  1. #1
    Registered User
    Join Date
    09-07-2013
    Location
    Chester
    MS-Off Ver
    Home: 2011 for Mac Work: 2007
    Posts
    70

    How to write Worksheet ChangeEvent if cell value is great than one

    Hello all

    Firstly to point out my VBA knowledge is very limited so apologies if this is an obvious one, I've managed to fudge together the below code which does work, however I have an issue when I attempt to run another macro via a button to clear certain cells.

    ChangeEvent2 runs if the value in M13 changes, which works fine until I run the Clear macro, which deletes the entry in M13, which I think then triggers ChangeEvent2 again. Excel appears to get stuck in a loop before crashing

    I'm thinking I could change ChangeEvent2 to only run if M13 value is great than 1 so not to be triggered when the Clear macro runs, how would I tweak ChangeEvent2 so that it only triggers if M13 value is greater than 1?

    Hopefully I've explained the situation clearly

    Many thanks in advance

    Twaddy

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: How to write Worksheet ChangeEvent if cell value is great than one

    Use Application.EnableEvents = False at the beginning of code to prevent worksheet_change event from triggering

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: How to write Worksheet ChangeEvent if cell value is great than one

    Stop the EVEN when launching "ChangeEvent2" to avoid to fire "Worksheet_Change" again


    Please Login or Register  to view this content.
    See also
    Please Login or Register  to view this content.
    - Battle without fear gives no glory - Just try

  4. #4
    Registered User
    Join Date
    09-07-2013
    Location
    Chester
    MS-Off Ver
    Home: 2011 for Mac Work: 2007
    Posts
    70

    Re: How to write Worksheet ChangeEvent if cell value is great than one

    Hi Stnkynts & PCI

    Thank you both for your replies, I'm still having problems I'm afraid although it does feel closer

    I've changed the code as below which works fine, however when I then record and apply the Clear Macro it does't run properly. I've created the clear Macro clearing all the cells I need however it then impacts the ChangeEvent if I enter figures again and only seems to run half of ChangeEvent2, please see 2nd section of code as to where I think it's failing

    Please Login or Register  to view this content.
    It seems to run this element ok and copy and pastes as it should

    Please Login or Register  to view this content.
    However seems to fall down when it tries to copy and paste the 2nd element of the code

    Please Login or Register  to view this content.
    I've tested the Clear macro without attempting to clear M13 and it works fine, it's just when I include M13 to be cleared that it fails

    This is a sample Clear macro I've recorded which does clear the cells but then stops the sheet working correctly if I try and use it again

    Please Login or Register  to view this content.
    Any further thoughts?

    Many thanks

    Twaddy

  5. #5
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: How to write Worksheet ChangeEvent if cell value is great than one

    Abandon your ChangeEvent1 and ChangeEvent3 from original post. They are pointless. Replace your Worksheet_Change event and Clear macro with the ones below. Does this accomplish what you are trying to do?

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    09-07-2013
    Location
    Chester
    MS-Off Ver
    Home: 2011 for Mac Work: 2007
    Posts
    70

    Re: How to write Worksheet ChangeEvent if cell value is great than one

    Thanks for your reply and your suggested coding, I'll give it a go

    Why are events 1 and 3 pointless? I want the sheet to move to the next cell to be completed in the form once the user has inputted data, and because of how the sheet is put together the cells don't run in a straight sequence

    Thanks

  7. #7
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: How to write Worksheet ChangeEvent if cell value is great than one

    "pointless" was the wrong choice of words. I apologize for that. What I should have said is that there are many more efficient ways of doing what you are trying to do. I still don't fully understand your workflow or else I would have coded a way for you to do it.

  8. #8
    Registered User
    Join Date
    09-07-2013
    Location
    Chester
    MS-Off Ver
    Home: 2011 for Mac Work: 2007
    Posts
    70

    Re: How to write Worksheet ChangeEvent if cell value is great than one

    No problem, no offence taken. I appreciate it's not easy trying to picture what I'm trying to achieve without seeing the sheet and partial coding, and I probably haven't explained myself very well

    To give some context to Events 1 and 3, which was originally just one event until I realised I needed to also incorporate event 2, the sheet is essentially a tool for employees to use to record their contract details and select various company benefits to demonstrate the value of their overall salary/reward package. As some cells that need completing run across the sheet, whereas other sections run down the sheet, and because I wanted to ensure all sections are completed to ensure all calculations work, I wanted the sheet to select the next cell in sequence automatically and this was the only way I knew how to achieve that, if you know of a better way then I'd be more than happy to learn and incorporate it.

    Thanks again for your help and patience

    Twaddy

  9. #9
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: How to write Worksheet ChangeEvent if cell value is great than one

    If it was me, I would look at setting up a custom UserForm. A UserForm will allow you to completely customize the data that they need to enter, with instructions, and once all data has been completed it will populate the spreadsheet. If you submit a copy of your workbook with sensitive information removed (try not to damage the integrity of the sheet) I could probably build you one.

    I just need to know what cells are required to be filled and what data needs to go where.

  10. #10
    Registered User
    Join Date
    09-07-2013
    Location
    Chester
    MS-Off Ver
    Home: 2011 for Mac Work: 2007
    Posts
    70

    Re: How to write Worksheet ChangeEvent if cell value is great than one

    Hi stnkynts
    That's very kind of you to offer, and in hindsight a Userform would probably have suited my needs better. I have built one before and may look to build one if I do a 2nd version of the sheet, however I need to launch it at work on Friday so time is against me
    Thanks again for all your help
    Cheers
    Greg

+ 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. ChangeEvent on Paste
    By cmore in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-11-2014, 05:12 PM
  2. Replies: 0
    Last Post: 07-31-2013, 03:26 PM
  3. Can a Function( ) called from within worksheet write to another cell?
    By 1Gunner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-19-2012, 04:19 PM
  4. Validation with ChangeEvent?
    By Ruthless in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-02-2006, 03:22 PM
  5. ChangeEvent
    By Shawn in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-18-2006, 05: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