+ Reply to Thread
Results 1 to 8 of 8

Prevent overwriting when copying back to other sheet

  1. #1
    Registered User
    Join Date
    08-15-2023
    Location
    Leeuwarden
    MS-Off Ver
    365
    Posts
    3

    Prevent overwriting when copying back to other sheet

    Hi,
    I've been searching a lot, but cannot find the right answer. I dont know much about VBA and programming so I hope you can help.
    I have two excel sheets, one called "Column lot etc" and one "Discarded". I'm trying to make a database in which whenever a column is discarded (Yes/No value) it goes to the discarded sheet. So far so good, that works fine without overwriting. Then I kind of superimpose that Sub to whenever someone made a mistake and wants to put it back all they have to do is put No into the cell in to the discarded sheet again. That works as well, but somehow this time it overwrites the same row over and over again, which already contains data. I cannot seem to find a good code for that that is fitting with the rest of my code (and yes I dont understand coding that much either, just snagged this off of internet and adapted it so that it hopefully works).
    In column lot etc sheet I have data from column B tm I that needs to be copied into "discarded" column A tm G.
    This is the working properly code for transferring the column lot etc to discarded
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

    Then this is the code for moving it back (which overwrites the same row over and over again)
    Please Login or Register  to view this content.
    Oh and i'm using office 365
    Hope you can help!
    Last edited by AliGW; 08-15-2023 at 10:51 AM. Reason: Code tags added. Please read the forum rules.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,896

    Re: Prevent overwriting when copying back to other sheet

    Welcome to the forum.

    Please review the forum rules regarding code tags. Thanks.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: Prevent overwriting when copying back to other sheet

    You think you can explain in a concise (kort maar krachtig) manner what you want to accomplish.
    Now we have to go through your code that does partially do what you want supposedly and not do what you want and everybody, most people anyway, do solve problems differently.
    BTW, the "On Error Resume Next" should be followed by "On Error GoTo 0".
    Experience trumps academics every day of the week and twice on Sunday.

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: Prevent overwriting when copying back to other sheet

    Does this transfer the "Yes" Rows?
    Not tested! Try on a Copy of your original.
    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: Prevent overwriting when copying back to other sheet

    It is assumed that both sheets have a header row (as they always should).
    Change references if and wher required.
    If your intention is to move cells from Column B to Column I in the Row where Column I has "Yes" in it's cell and delete this same range after, this should do that
    The pasting of these cells will be in the first empty cell in Column A in the 2nd sheet.
    Please Login or Register  to view this content.

    If your intention is to move cells from Column A to Column H in the Row where Column H has "No" in it's cell and delete this same range after, this should do that
    The pasting of these cells will be in the first empty cell in Column A in the 1st sheet.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    08-15-2023
    Location
    Leeuwarden
    MS-Off Ver
    365
    Posts
    3

    Re: Prevent overwriting when copying back to other sheet

    Hi Jolivanes,

    Well, I admit it was wishfull thinking, I was hoping someone had a solution for me. I noticed different solutions which only confused me as I dont know a lot about VBA.
    Anyway, thanks so much for your replies!

    I Tried the Sub With_Autofilter, but it had an error (no cells are found, Range("B2:I" & lr).SpecialCells(12).Copy Sheets("Discarded").Cells(Rows.Count, "A").End(xlUp)(2) was highlighted ) and as Sub MoveToDiscarded is working well for me I don't see why we need to resolve this.

    Sub Return_With_Autofilter works, but not in the way I need it to work. It didnt come to my mind that there is a table with drop down menu's in there as well and therefore the program probably thinks the cell is already filled? Because all the data ends up below my table range. So that means it needs to not overwrite the cell that is taken in column B in sheet Column lot etc but columns C tm I in the same row as empty B cell can be overwritten. Yes I know this is quite challenging and not easy . I really appreciate your help!

  7. #7
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: Prevent overwriting when copying back to other sheet

    If we had known that it was tables you're dealing with, things would have been different.
    Attach a representative workbook to avoid confusion.
    It explains at the top in the top yellow banner how to do this.

  8. #8
    Registered User
    Join Date
    08-15-2023
    Location
    Leeuwarden
    MS-Off Ver
    365
    Posts
    3

    Re: Prevent overwriting when copying back to other sheet

    Quote Originally Posted by jolivanes View Post
    If we had known that it was tables you're dealing with, things would have been different.
    Attach a representative workbook to avoid confusion.
    It explains at the top in the top yellow banner how to do this.
    I'm sorry, I realized it after it copied below the table that the cells were not 'empty'. I cannot share the excel, it has sensitive information from the company I work for. I'm going on holidays after today, so I'll just let them copy it back themselves in this case. I really really appreciate all the time you put in here, I learned a lot from it (although it might not seem like it to you). I will come back to it after my holidays in a few weeks if that is ok with you, then I'll prepare a dummy excel without the sensitive info and we can look at it again. Would like to see how this needs to be resolved!
    Thanks again!
    Last edited by FranItsMe; 08-17-2023 at 03:39 AM.

+ 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. [SOLVED] Prevent overwriting cells with formulas
    By louvaek in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 12-05-2018, 01:59 PM
  2. [SOLVED] Prevent overwriting when saving as pdf
    By Jacc in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-26-2017, 01:30 PM
  3. Overwriting a cell, copying the new value, and then "undoing" back to original val.
    By chuggins143 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-25-2010, 05:56 PM
  4. lock Subtotals to prevent overwriting.
    By gruf1968 in forum Excel General
    Replies: 1
    Last Post: 03-12-2010, 07:01 PM
  5. Prevent overwriting cells
    By MGT2000 in forum Excel General
    Replies: 0
    Last Post: 10-29-2008, 02:11 PM
  6. Prevent overwriting file...
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-11-2008, 11:47 AM
  7. How to prevent overwriting of file ?
    By asitagrawal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-25-2008, 10:23 AM

Tags for this Thread

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