+ Reply to Thread
Results 1 to 22 of 22

Macro Adjustment Needed To Stop Deleting Row When Cancelled

  1. #1
    Forum Contributor
    Join Date
    07-07-2008
    Location
    sCOTLAND
    MS-Off Ver
    Office 2003 SP3
    Posts
    256

    Macro Adjustment Needed To Stop Deleting Row When Cancelled

    Hi

    I have a Macro that brings up a a UserForm when a cell is clicked, it works well but whenever the Row & Column header is clicked and it highlights the entire row / column the UserForm comes up, that is ok but if i click cancel it deletes everything in the entire row / column. Is there away to fix this so that the userform only comes up when the actual cell is clicked? or it does not delete anything when cancelled? I have added the macro below.

    Thanks
    Please Login or Register  to view this content.

    The userform code

    Please Login or Register  to view this content.
    Last edited by JimmiOO; 08-24-2010 at 02:42 AM.

  2. #2
    Forum Contributor
    Join Date
    07-07-2008
    Location
    sCOTLAND
    MS-Off Ver
    Office 2003 SP3
    Posts
    256

    Re: Macro Adjustment Needed To Stop Deleting Row When Cancelled

    Anyone know how to sort this problem?

  3. #3
    Forum Contributor
    Join Date
    07-07-2008
    Location
    sCOTLAND
    MS-Off Ver
    Office 2003 SP3
    Posts
    256

    Re: Macro Adjustment Needed To Stop Deleting Row When Cancelled

    Anyone shed some light on this?

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,377

    Re: Macro Adjustment Needed To Stop Deleting Row When Cancelled

    It would be easier to work on the problem if you uploaded a dummy workbook with some typical data and an outline of what the process should do.

    At the moment, anyone thinking of helping will need to guess what the form looks like and what you're trying to do.

    Regards

  5. #5
    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: Macro Adjustment Needed To Stop Deleting Row When Cancelled

    Maybe like this:
    Please Login or Register  to view this content.
    Please change the QUOTE tags in your first post to CODE tags.
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Forum Contributor
    Join Date
    07-07-2008
    Location
    sCOTLAND
    MS-Off Ver
    Office 2003 SP3
    Posts
    256

    Re: Macro Adjustment Needed To Stop Deleting Row When Cancelled

    Hi shg

    I have tried your code and i am getting a run time error if i click anywhere in the row other than the cell that brings the userform up. when i do a debug i it is highlighting thgis bit of code

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    07-07-2008
    Location
    sCOTLAND
    MS-Off Ver
    Office 2003 SP3
    Posts
    256

    Re: Macro Adjustment Needed To Stop Deleting Row When Cancelled

    Hi shg

    I have tried your code and i am getting a run time error if i click anywhere in the row other than the cell that brings the userform up. when i do a debug i it is highlighting thgis bit of code

    Please Login or Register  to view this content.

    I have to click in other cells in the row before i use the userform

    Thanks for the help though, very much appreciated

  8. #8
    Forum Contributor
    Join Date
    07-07-2008
    Location
    sCOTLAND
    MS-Off Ver
    Office 2003 SP3
    Posts
    256

    Re: Macro Adjustment Needed To Stop Deleting Row When Cancelled

    I have added a sample sheet to show you what i mean.

    On the sample if you click on the box all is good, If you click on the J column the box appears if you cancel it fills the column with text, if you click on the I column the box appears and when you cancell it delets the entire column.

    Can this be fixed? I don,t mind if the box comes up when the column is clicked as long as when you click cancel it leaves everything the way it was
    Last edited by JimmiOO; 08-24-2010 at 02:41 AM.

  9. #9
    Forum Contributor
    Join Date
    07-07-2008
    Location
    sCOTLAND
    MS-Off Ver
    Office 2003 SP3
    Posts
    256

    Re: Macro Adjustment Needed To Stop Deleting Row When Cancelled

    Tried a few things but not having much luck with this at all.

  10. #10
    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: Macro Adjustment Needed To Stop Deleting Row When Cancelled

    I still don't understand what the code is supposed to do, but my suggestion has an error. Change to

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    07-07-2008
    Location
    sCOTLAND
    MS-Off Ver
    Office 2003 SP3
    Posts
    256

    Re: Macro Adjustment Needed To Stop Deleting Row When Cancelled

    Hi shg

    If you open the sample and click on any the boxes at the top a userform will appear and you just enter a number that relates to spreadsheet and a date, its just a quick way to insert theinfo thats needed in them boxes. The problem i am getting is when i highlight any row on the top the userform comes up, when i click cancel it deletes all the data in the entire row. I still need the userform to appear when any the boxes either I2 , L2, O2, R2, U2, X2, AA2, AD2 is clicked.

    I have tried your updated cade by now the user form does not come up when i click in box, in the sample it is I2

  12. #12
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Macro Adjustment Needed To Stop Deleting Row When Cancelled

    Perhaps the control properties on the userform have a rowsource specified that is writing back nothing when you exit the userform? The code wouldn't show the problem. It would be the settings of properties on the userform.

  13. #13
    Forum Contributor
    Join Date
    07-07-2008
    Location
    sCOTLAND
    MS-Off Ver
    Office 2003 SP3
    Posts
    256

    Re: Macro Adjustment Needed To Stop Deleting Row When Cancelled

    Quote Originally Posted by MarvinP View Post
    Perhaps the control properties on the userform have a rowsource specified that is writing back nothing when you exit the userform? The code wouldn't show the problem. It would be the settings of properties on the userform.
    I don't see anything unusual in the properties?

  14. #14
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Macro Adjustment Needed To Stop Deleting Row When Cancelled

    Do you know how to set a breakpoint and step through your code? This is a great way to solve your problem.

  15. #15
    Forum Contributor
    Join Date
    07-07-2008
    Location
    sCOTLAND
    MS-Off Ver
    Office 2003 SP3
    Posts
    256

    Re: Macro Adjustment Needed To Stop Deleting Row When Cancelled

    Hi Marvin i don't yet, could you explain and i will give it a go?
    Last edited by shg; 08-23-2010 at 12:29 PM. Reason: deleted quote

  16. #16
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Macro Adjustment Needed To Stop Deleting Row When Cancelled

    View your code and click on the margin next to the first statement past the Dim statements. For you it would be the screenupdating... A big red dot appears. This tells the code to stop when it hits this point. You then run your code, do whatever you do to get it running. All of a sudden the code stops and a yellow highlight shows on the line you specified. You then F8 or step through the code one line at a time and see what it does. You can hover over variables and it will tell you what value they are.
    You should be able to step through your code and see which statement deletes that row/column and fix it.

    You can set multiple breakpoints in your code. You should set a breakpoint also in your Userform Code to see if the problem is happening there also.

    You'll be a VBA guru in no time!
    Last edited by MarvinP; 08-23-2010 at 11:22 AM.

  17. #17
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Macro Adjustment Needed To Stop Deleting Row When Cancelled

    Add:
    Please Login or Register  to view this content.
    to the top of the sub.
    Remember what the dormouse said
    Feed your head

  18. #18
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Macro Adjustment Needed To Stop Deleting Row When Cancelled

    Here is a link about Debugging VBA Code
    I use the Immediate window a lot to see if my syntax is correct and step through code all the time to see why things don't work.

  19. #19
    Forum Contributor
    Join Date
    07-07-2008
    Location
    sCOTLAND
    MS-Off Ver
    Office 2003 SP3
    Posts
    256

    Re: Macro Adjustment Needed To Stop Deleting Row When Cancelled

    Quote Originally Posted by MarvinP View Post
    View your code and click on the margin next to the first statement past the Dim statements. For you it would be the screenupdating... A big red dot appears. This tells the code to stop when it hits this point. You then run your code, do whatever you do to get it running. All of a sudden the code stops and a yellow highlight shows on the line you specified. You then F8 or step through the code one line at a time and see what it does. You can hover over variables and it will tell you what value they are.
    You should be able to step through your code and see which statement deletes that row/column and fix it.

    You can set multiple breakpoints in your code. You should set a breakpoint also in your Userform Code to see if the problem is happening there also.

    You'll be a VBA guru in no time!
    Marvin thanks very much i have went through the code and this will come in very very handy, however the problem i have hear is the code is working fine and doing what i want it to do, it is only when i highlight the column then click cancel the error occurs, i am not sure how i would replicate that to see whats happening.

  20. #20
    Forum Contributor
    Join Date
    07-07-2008
    Location
    sCOTLAND
    MS-Off Ver
    Office 2003 SP3
    Posts
    256

    Re: Macro Adjustment Needed To Stop Deleting Row When Cancelled

    Quote Originally Posted by romperstomper View Post
    Add:
    Please Login or Register  to view this content.
    to the top of the sub.
    Romperstomper that has fixed the problem, thanks you very much, can you tell me how you managed to see the problem so i can try myself to see what was going wrong?

    Thanks for all the help everyone

  21. #21
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Macro Adjustment Needed To Stop Deleting Row When Cancelled

    You said you didn't want the form popping up if you selected an entire column, so I just added a test so that if the selection had as many rows as there are rows on the sheet, the sub stopped.

  22. #22
    Forum Contributor
    Join Date
    07-07-2008
    Location
    sCOTLAND
    MS-Off Ver
    Office 2003 SP3
    Posts
    256

    Re: Macro Adjustment Needed To Stop Deleting Row When Cancelled

    Quote Originally Posted by romperstomper View Post
    You said you didn't want the form popping up if you selected an entire column, so I just added a test so that if the selection had as many rows as there are rows on the sheet, the sub stopped.

    Thank you, i have learned quite a lot on this, Problem Solved.

+ 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