+ Reply to Thread
Results 1 to 13 of 13

Change Event not working

  1. #1
    Registered User
    Join Date
    03-06-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    28

    Change Event not working

    Cells in Column M have a data validation drop-down list. If the user selects 'Closed', I want this code to run:

    Please Login or Register  to view this content.
    This code works fine run on its own. But as soon as I run it from the change event (code below) it falls over.

    Please Login or Register  to view this content.
    I get a Type Mismatch on If Target.Value = "Closed" Then. Can someone explain why this is happening?

    -Militia

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Change Event not working

    Have you got the change event in the correct sheet?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Change Event not working

    Your main code works better like this
    Please Login or Register  to view this content.
    It will copy the data from the activecell's row to "Closed" depending on the entry in M
    Attached Files Attached Files

  4. #4
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Change Event not working

    Hi, It seems to me that because it is a "Change Event" and the Target Has to equal "Closed". You need to enter the word "Closed " In your Column "M" Range. Then it works for me, else you could use The "Selection Change Event".
    NB:- I did get your "Error" when I tried Dragging some Cells in you Range, But that can be overcome. (If Target.count = 1 then)
    Regards Mick

  5. #5
    Registered User
    Join Date
    03-06-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Change Event not working

    RoyUK - Firstly, thanks for the improvement to my code. One problem though, when run I get message "Application defined or object defined error" on line .Range(Cells(LastRow, 4), .Cells(LastRow, 14)).Validation.Delete. Why might this be?

    I've been putting my change event in the sheet where the change will be made. Is that where it should be?

    MickG - I'm very new to writing code, until now i've begged and stole code. I can't find much about on SelectionChange Event. I tried just changing the first line without success.

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Change Event not working

    The sheet event code needs to be in the sheet that contains the data. For it to work the entry in Colmn M should be changed to Closed, at which point the line will be cut to the Closed sheet.

    When you get the error do the cells in that range have any Data validation?

  7. #7
    Registered User
    Join Date
    03-06-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Change Event not working

    Thats the exact setup i've got.

    I've found something very strange. Where I said your code is falling over, I stepped through it to see if i get any clues. What I found was, If my screen is displaying the "Closed" sheet, it works as it should. But if it is displaying the "Open" sheet (where the data is originally), which it would do at the moment, it falls over.

    I've now added in a line and it works fine, ever come across that before?

    Please Login or Register  to view this content.
    Despite this, i still have a problem in getting my change event up and running. I know it can be done as I've found several cases of where people have a drop down and each item, when selected, calls a sub routine. But i've found nothing quite like this, do you think it is possible?

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Change Event not working

    Can you attach the workbook?

  9. #9
    Registered User
    Join Date
    03-06-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Change Event not working

    I've attached the work book. You will notice i've commented out the Change Event code as it causes your code to fall over if it isn't.

    Many thanks
    Attached Files Attached Files

  10. #10
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Change Event not working

    Try this, although your open table ends up with empty rows.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    03-06-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Change Event not working

    Good morning RoyUk

    After you made your changes the code no longer falls over on that line. Despite this, it still istn't working. I now get "Compile Error: Can't find project or library" and it highlights the word "Date" on this line .Cells(LastRow + 1, 14).Value = Format(Date, "m/d/yyyy")

    I know I haven't coded to remove that blank line, but I will do. This is the first project i've done like this and I sure have learnt a lot - a bit of planning would have gone a long way.

    Cheers
    -Militia

  12. #12
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Change Event not working

    In the VBE, do Tools > References, and look at the ticked items (they are all at the top). Look for one that says MISSING and untick it.
    Entia non sunt multiplicanda sine necessitate

  13. #13
    Registered User
    Join Date
    03-06-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Change Event not working

    Quote Originally Posted by shg View Post
    In the VBE, do Tools > References, and look at the ticked items (they are all at the top). Look for one that says MISSING and untick it.
    Thanks for your input, though I don't a Reference ticked called MISSING.

+ 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