+ Reply to Thread
Results 1 to 41 of 41

Deleting same row on different sheets within a workbook

  1. #1
    Registered User
    Join Date
    04-11-2009
    Location
    Stockton on Tees, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Deleting same row on different sheets within a workbook

    Hello All,
    I am creating a tracking system for assessment in school. If you can image I have six sheets which all relate to different areas of the curriculum. However, on every sheet I have the same name in the same cells. So, Sheet 1 might be Geography and Sheet 2 Art but each child's name always appear in the same cells. The first child's surname 'Bloggs' appears in cell M15 and his forename 'Joe' appears in N15. Image the third child down leaves. I want to create a button that will automatically delete the same row in each of the worksheets so that the child's data disappears. I have other worksheets in the workbook that are not connected and simply analyse the data so I wouldn't want these affected.
    The trouble is that it won't be the same child (or row) every time so I would need to know how to select a new child. I am a bit of a novice so would need really clear instructions on how to do this. I think a could get as far as creating the command button if that's what I need but I would be lost after that. The workbook is protected so I don't know if this causes a problem?
    Thank you for any help

  2. #2
    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: Deleting same row on different sheets within a workbook

    Maybe you don't need a macro for this.

    An often overlooked fearture of Excel is the ability to enter/delete/amend data on multiple sheets simultaneously.

    Try this

    1/. Hold down the ctrl key and select the tabs you need to amend, say Sheet1,Sheet2, and Sheet3

    2/. Release the key.

    3/. Anything you do on the visible sheet will now be repeated in the other sheets.

    4/. Once you select another tab the repeat facility is cancelled.
    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.

  3. #3
    Registered User
    Join Date
    04-11-2009
    Location
    Stockton on Tees, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Deleting same row on different sheets within a workbook

    Thank you for your answer. To be honest your method would be the easiest and if I were the only one using the workbook then I would just do this. The trouble is that lots of people will use the information and I won't always be there to help. I also intend to hide the sheet tabs - my staff manage to 'kill' anything where they have too much access. I'd like to make it as resilient and 'teacher proof' as possible lol

  4. #4
    Registered User
    Join Date
    04-11-2009
    Location
    Stockton on Tees, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Deleting same row on different sheets within a workbook

    Is there anyone who can help me with this. You'd make a huge difference to over 300 children!!

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Deleting same row on different sheets within a workbook

    Hi Fidget

    I'd suggest using a UserForm for this. Populate (with Code) a ListBox or ComboBox on the UserForm with the Unique Child Names.

    Have the User select a Name from the presented list, push a Button and delete that Child from all appropriate worksheets (with code). Marcol's suggestion could be automated to do this or simply loop through the appropriately Named sheets to do the delete.

    If you need help on this please post your workbook.

    Protection can/will affect this but there are ways around that.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  6. #6
    Registered User
    Join Date
    04-11-2009
    Location
    Stockton on Tees, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Deleting same row on different sheets within a workbook

    Thank you so much.

    Please find attached workbook. It was much too big so I have had to delete loads of sheets which may affect functionality (sorry!)Basically there were lots of other sheets nut these would be the only ones where the whole row would need to be deleted. Reception.xlsm. To unprotect press ctrl + b and the password is run (lowercase).

    If you look on the sheet named PSED you can see that column N and M contain children's names. These are populated from the 'pupil details' sheet. In effect, therefore, I would want to be able to delete the child's name from the 'Pupil Details' sheet and the same row disappear from the PSED,UW,CL,PH, LIT, EAD and MAT sheet.

    Would it be possible to create something like an IF function where you would type the child's name in the box and it deletes the whole row in all of those sheets. Even better would be if you could just give the number of the row to delete and pressed a button and it did it for you?

    Any help would be great x

  7. #7
    Registered User
    Join Date
    04-11-2009
    Location
    Stockton on Tees, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Deleting same row on different sheets within a workbook

    Reception.xlsmI attached it. Where does it appear - have you got it?? I'll have another go!

  8. #8
    Registered User
    Join Date
    04-11-2009
    Location
    Stockton on Tees, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Deleting same row on different sheets within a workbook

    Can anyone help - I know it's tricky but great fun. Don't abandon me jaslake - I have every faith x

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Deleting same row on different sheets within a workbook

    Hi Fidget

    Haven't abandoned you...looking at your file and mocking up code as we speak.

  10. #10
    Registered User
    Join Date
    04-11-2009
    Location
    Stockton on Tees, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Deleting same row on different sheets within a workbook

    What a star x

  11. #11
    Registered User
    Join Date
    04-11-2009
    Location
    Stockton on Tees, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Deleting same row on different sheets within a workbook

    Thought I'd look up Atwood Lake as you suggest. Looks very nice. Do you enjoy all the water pursuits on offer. Very different to where I live - have a look too!

  12. #12
    Registered User
    Join Date
    04-11-2009
    Location
    Stockton on Tees, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Deleting same row on different sheets within a workbook

    Where are all you excel wizards??? I have been fascinated before- please do it again

  13. #13
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Deleting same row on different sheets within a workbook

    Hi Fidget

    Don't get your shorts caught in your nickers...sit back...relax...have a smoke if you've got 'em.

    We all have issues we need to tend to.

  14. #14
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Deleting same row on different sheets within a workbook

    Hi Fidget

    Try the code in the attached...let me know of issues.
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    04-11-2009
    Location
    Stockton on Tees, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Deleting same row on different sheets within a workbook

    That seems to work brilliantly but how do I replicate it in my much bigger file? Could you give me a bit of an idiots guide to how I do it. I can copy codes etc from the one you have sent me if that helps?

  16. #16
    Registered User
    Join Date
    04-11-2009
    Location
    Stockton on Tees, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Deleting same row on different sheets within a workbook

    Hi jaslake
    Thank you so much for your work. I seem to be getting there . I have had to move the children's names down to row 15 in the Pupil Details sheet. I'm sure this will make a difference to the code. Could you let me know which bit please?

  17. #17
    Registered User
    Join Date
    04-11-2009
    Location
    Stockton on Tees, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Deleting same row on different sheets within a workbook

    Hi Again Jaslake,

    I have transferred everything (I think!) into my own document. It is deleting the child's information from the Pupil Detail sheet but then in the other sheets it appears to be just dleting the information and leaving a hash ref error?

  18. #18
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Deleting same row on different sheets within a workbook

    Hi Fidget

    I'm responding to your question
    how do I replicate it in my much bigger file
    First look in your "much bigger file and see if you have a UserForm called UserForm2.frm. If you do, let me know. If you don't proceed as follows:


    Download and open the file from Post #14 Reception v7.xlsm
    Get into VBA (Alt +F11)
    Highlite UserForm2 (don't open it, merely Highlite the Name)
    From the top Ribbon select File---->Export
    You'll see a screen like this
    Export Screen.jpg

    Navigate to a location that you will REMEMBER (like your Desktop perhaps...don't care...just remember it).
    Click Save.
    Close the file Post #14 Reception v7.xlsm
    Open your "much bigger file"
    Get into VBA (Alt +F11)
    From the top Ribbon select File---->Import
    Navigate to the location that you REMEMBERED (like your Desktop perhaps...)
    You'll see a screen like this
    Import Screen.jpg

    Highlite UserForm2.frm
    Click Open
    A UserForm called UserForm2.frm will be loaded into your "much bigger file"

    Go back to the workbook--->Pupil Details Worksheet
    Get into "Design Mode"...top Ribbon...Developer----->Design Mode---->Insert---->ActiveX Controls---->Command Button
    Draw a Button on Pupil Details Worksheet
    Right Click on the Button Select View Code
    Modify the code to look like this (don't change the Procedure Name...simply add the line of code as indicated)
    Code.jpg

    Go back to Pupil Details Worksheet...Exit Design Mode.
    Save the File.
    Things should now work.

    Let me know of issues.

  19. #19
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Deleting same row on different sheets within a workbook

    Hi Fidget

    Yes, this will affect the Code
    Please Login or Register  to view this content.
    On which sheets did you make this move?

  20. #20
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Deleting same row on different sheets within a workbook

    Hi Fidget

    Don't know
    It is deleting the child's information from the Pupil Detail sheet but then in the other sheets it appears to be just dleting the information and leaving a hash ref error?
    This does not happen on the Sample File. Post your workbook (with Code)...zip it if you have to.

  21. #21
    Registered User
    Join Date
    04-11-2009
    Location
    Stockton on Tees, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Deleting same row on different sheets within a workbook

    I have had to move the children's names down from row 13 to row 15 on the pupil details sheet. All other sheets remain the same ( they were already started on row 15).

  22. #22
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Deleting same row on different sheets within a workbook

    Hi Fidget

    I could probably guess and just insert two new rows in Pupil Details Worksheet and it may or may not work. I'd prefer to see the new file structure and so I can test any changes.

    Otherwise you can try changing this line of code from
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    and this line of code from
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  23. #23
    Registered User
    Join Date
    04-11-2009
    Location
    Stockton on Tees, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Deleting same row on different sheets within a workbook

    I think it might be sorted!! You are a wonder x

  24. #24
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Deleting same row on different sheets within a workbook

    Hi Fidget

    Good...let me know.

  25. #25
    Registered User
    Join Date
    04-11-2009
    Location
    Stockton on Tees, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Deleting same row on different sheets within a workbook

    The only problem that remains is that I can only do all of it when the sheet is unprotected. Is there any way to get it to work with the protection on? When I unprotect it people always seem to 'kill it' ha ha x

  26. #26
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Deleting same row on different sheets within a workbook

    Hi Fidget

    Yes, we can do this
    Is there any way to get it to work with the protection on
    Have Family tonight for dinner so it'll be later tonight or tomorrow.

  27. #27
    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: Deleting same row on different sheets within a workbook

    Hmm?
    I'm not entirely clear with what you are trying to do, but it seems to me at least, that you are going about it the hard way.

    Okay, why go the easy way when there is a hard way? ...

    1/. Never use merged cells on Data sheets, they cause nothing but grief ...

    2/. Comand buttons are best avoided, where possible. Use the Worksheet_SelectionChange event instead.

    3/. You have formulae and lists buried in your sheets, you'll soon forget where the are, and accidently delete/overwrite them!
    Better to put Lookup Lists on a seperate Lookup Sheet.
    In this cases the are not required, have a look at the new formulae, to see the differences.

    4/. I'm not sure what this type of formula is for, so I've left them in for now.
    What are you sub-totalling?
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Maybe this could used instead?
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Try this workbook.

    Navigate to another sheet by choosing from the drop-down in B2, and return by selecting "Home"

    Enter the name to be erased in cells H5:I5, then select "GO". (Try a few misspellings.)

    There are a few other things to handle, but we can look at these later, if I'm on an acceptable track.
    Attached Files Attached Files
    Last edited by Marcol; 11-19-2012 at 02:24 PM.

  28. #28
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Deleting same row on different sheets within a workbook

    Hi Fidget

    Add this code to your Workbook.Open Event. This will allow you to delete rows on the protected sheets.
    Please Login or Register  to view this content.

  29. #29
    Registered User
    Join Date
    04-11-2009
    Location
    Stockton on Tees, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Deleting same row on different sheets within a workbook

    Hi Jaslake,

    Thank you but I'm not sure what you mean when you say add it to your Workbook.Open Event - please explain, I'm sorry to be a pain

  30. #30
    Registered User
    Join Date
    04-11-2009
    Location
    Stockton on Tees, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Deleting same row on different sheets within a workbook

    Thank you for your help too Marcol x

  31. #31
    Registered User
    Join Date
    04-11-2009
    Location
    Stockton on Tees, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Deleting same row on different sheets within a workbook

    Hi jaslake. I know how to get it to run when I open it but there's already lots in there and I'm getting a compile error/ambigious name message??

  32. #32
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Deleting same row on different sheets within a workbook

    Hi Fidget

    On a copy of your file replace your Workbook_Open Event with this Code...you can uncomment other lines as required. Let's get it working for you. Replace the code...save the workbook...close it...reopen it...run the code.
    Please Login or Register  to view this content.
    Let me know of issues.

  33. #33
    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: Deleting same row on different sheets within a workbook

    To both.

    Take a step back and think about it.

    Anybody will eventually patch a badly designed workbook, but why?

  34. #34
    Registered User
    Join Date
    04-11-2009
    Location
    Stockton on Tees, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Deleting same row on different sheets within a workbook

    Jaslake,
    Thank you for helping me with the my workbook. It is far from perfect (and I realise that) but you've ignored that and just helped me resolve the issues. Will try the last bit, thanks again x

  35. #35
    Registered User
    Join Date
    04-11-2009
    Location
    Stockton on Tees, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Deleting same row on different sheets within a workbook

    Delete Method of Range Class Failed

    Hi Jaslake have completed the last bit and I'm not getting this message when I try to delete a pupil with the protection on. It works fine when the sheet id not protected. Any ideas?

  36. #36
    Registered User
    Join Date
    04-11-2009
    Location
    Stockton on Tees, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Deleting same row on different sheets within a workbook

    Marcol, Thank you for your comment. You are really good with excel and I'm not (unfortunately). I am, however, a really good teacher and I'm trying my best with the limited knowledge that I have. It would be lovely to have somebody with your expertise to make these things for me but I don't so I'm just cracking on - please be patient and thank you again

  37. #37
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Deleting same row on different sheets within a workbook

    Hi Fidget

    It's been a long day and I'm a bit obtuse at this point but I don't follow...it seems to me these statements are a bit contradictory
    I'm not getting this message when I try to delete a pupil with the protection on.
    It works fine when the sheet id not protected
    What is Sheet ID? I have no sheet called "sheet id" in the workbook I have...you've got me confused.

  38. #38
    Registered User
    Join Date
    04-11-2009
    Location
    Stockton on Tees, England
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Deleting same row on different sheets within a workbook

    Hey Jaslake - I think excel had fallen out with me!! All working fine now and I haven't changed anything. You excel at excel!! Hope you had a lovely meal with your family. Sorry for the confusion- think I'm a bit tired. Thanks againx

  39. #39
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Deleting same row on different sheets within a workbook

    Hi Fidget

    Your Great Country gave us this Holiday to celebrate...so from me to you...Happy Thanksgiving...see you after the Holiday.

  40. #40
    Registered User
    Join Date
    11-21-2012
    Location
    malaysia
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Deleting same row on different sheets within a workbook

    Hi there,

    If i accidentally deleted a student, how to UNDO it?

  41. #41
    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: Deleting same row on different sheets within a workbook

    Hi processceci
    You shouldn't really ask new questions in someone elses' thread, see the forum rules Rule 2.

    However this is a good point that you raise.

    VBa cancels the "Undo" facility in Excel when code is run, this can be dangerous, and for me at least is a good reason for avoiding VBa wherever possible.

    Here are some options to try.

    1/. Write your code to store the data as variables before deleting the rows/data. This would allow further code to recover data deleted in error. This will only work until the code stops, or the workbook is closed.

    2/. Write the data to a very hidden sheet instead of deleting it. This way data is retained permanently, and can be recovered to the live sheets as required.

    3/. Write the Data to an external file during the deleting operation.

    4/. Save a backup file via the code as it goes.

+ 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