+ Reply to Thread
Results 1 to 16 of 16

Disable macro when inserting/deleting rows

  1. #1
    Registered User
    Join Date
    09-24-2009
    Location
    Middletown, CT
    MS-Off Ver
    Excel 2003
    Posts
    31

    Disable macro when inserting/deleting rows

    Hi,

    Is there a way for a macro to be not active when trying to insert a row or a way to have the macro understand that it's just a row shift? I'm trying to have a time stamp that anyone changes the value in a column. The following code generates an error 1004: application or object defined error when I insert or delete a row

    Please Login or Register  to view this content.
    Last edited by aznprod517; 10-29-2009 at 09:41 AM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Disable macro when inserting/deleting rows

    have a look at

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    09-24-2009
    Location
    Middletown, CT
    MS-Off Ver
    Excel 2003
    Posts
    31

    Re: Disable macro when inserting/deleting rows

    Thanks, I can now insert the rows fine, but I realize now the code doesn't fire afterwards? This is my code after the modification. I had a second portion of the code in another IF statement that worked fine previously.

    Please Login or Register  to view this content.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Disable macro when inserting/deleting rows

    You need to detail what has to be done on the sheet in order for it to work.

    If I select F1:F3 and change the contents then the event fires. The final set of code is not executed because the IF test fails rather than anything to do with Enabling events.

  5. #5
    Registered User
    Join Date
    09-24-2009
    Location
    Middletown, CT
    MS-Off Ver
    Excel 2003
    Posts
    31

    Re: Disable macro when inserting/deleting rows

    I apologize for not being more clear. I have columns A-I and about 2000 rows of information. User inputs information in columns A,B, & F. Those are blank slots until they fill in the information. Columns C, D, G-I have formulas within them. I want the formula to carry down if they insert rows because of changing situations (2nd IF statement). However, if they change anything in column F, I want column E to record when they changed it (1st IF statement). So both macros need to be running concurrently in the background.

    I can't attach the file for some reason right now.

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Disable macro when inserting/deleting rows

    What happens if you but a break line on the

    Please Login or Register  to view this content.
    And then step through the code. Is the IF test statisfied?

  7. #7
    Registered User
    Join Date
    09-24-2009
    Location
    Middletown, CT
    MS-Off Ver
    Excel 2003
    Posts
    31

    Re: Disable macro when inserting/deleting rows

    If I just put in the break anywhere, then nothing works. I put the Application.EnableEvents = true after the final IF statement but then it applies the change to every cell in that row from A to IV.

    Please Login or Register  to view this content.

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Disable macro when inserting/deleting rows

    You just turn your code upside down

    post back when you have a sample file.

  9. #9
    Registered User
    Join Date
    09-24-2009
    Location
    Middletown, CT
    MS-Off Ver
    Excel 2003
    Posts
    31

    Re: Disable macro when inserting/deleting rows

    I fixed the code back to the original format. Sorry for the switch. I know sometimes the logical flow of the statements can make it work or not, but it still doesn't. I have attached a sample file on. Has things for the first 50 or so rows. Same problems still crops up though in that if I add a row or delete a row, it will time stamp everything in that row.
    Attached Files Attached Files

  10. #10
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Disable macro when inserting/deleting rows

    If I change the contents of F3 then the event fires.
    The date stamp is added to E3.

    But the IF test fails as Target.cells = 1 and
    Columns.Count * Target.Rows.Count = (256*1) = 256

    Are you sure your IF test is correct?

  11. #11
    Registered User
    Join Date
    09-24-2009
    Location
    Middletown, CT
    MS-Off Ver
    Excel 2003
    Posts
    31

    Re: Disable macro when inserting/deleting rows

    I believe so. For some reason only one IF statement will work at each time. It just needs to carry the formula down if a row is inserted and record a change in column F when it happens. When I debug it right now, it highlights the

    'next cell' line.

    It still keeps on time stamping every cell in the row that is inserted.

    I believe so. Before I inserted the time stamp function, it worked properly, albeit a bit laggardly.

  12. #12
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Disable macro when inserting/deleting rows

    Well I just commented out the time stamp part and change F3. The test does not pass. so nothing is executed.

    You need to detail what I have to do in order to get the code to work as expected.

    As I say I am changing F3. What should I be doing??

  13. #13
    Registered User
    Join Date
    09-24-2009
    Location
    Middletown, CT
    MS-Off Ver
    Excel 2003
    Posts
    31

    Re: Disable macro when inserting/deleting rows

    As something gets entered into any cell in column F, or in this case, F3, it should give a time stamp in E3. Same goes for F4 -> E4, F5 -> E5 etc.

    The problem is right now is that inserting a row in row 2, the code will not execute properly and either give an error without the break statements, or will post the time stamp in every cell in that row with the time statement.

    In addition, there are referencing formulas in columns C,G,H, I that need to be carried down if a row is inserted.

    The non-execution is weird. It happens only after I terminate the macro. I would need to reopen the file again before it runs again.

    Is there a way to code it as, if I am inserting row, there will be no time stamp, but the formulas will carry down?

  14. #14
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Disable macro when inserting/deleting rows

    Try the following change.

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    09-24-2009
    Location
    Middletown, CT
    MS-Off Ver
    Excel 2003
    Posts
    31

    Re: Disable macro when inserting/deleting rows

    Thanks, it works great! Thanks again for all your help.

  16. #16
    Registered User
    Join Date
    09-24-2009
    Location
    Middletown, CT
    MS-Off Ver
    Excel 2003
    Posts
    31

    [SOLVED] Disable macro when inserting/deleting rows

    Thanks again

+ 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