+ Reply to Thread
Results 1 to 24 of 24

Move row to different table depending on cell value

  1. #1
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Move row to different table depending on cell value

    Hello everyone,

    Added workbook has an example added.

    There are two tables on this workbook: Rewatching and Rewatched.
    I want to move entire rows, plus the comments with pictures added, from Rewatching to Rewatched if the cell in column G in the table Rewatching = "Completed".
    The value in column G is updated with a formula.

    In the added workbook row 9 should be moved to Rewatched, as the value in G9 = "Completed".

    The code should also check whether or not the title in column A is already present. If it is, it only has to update the value in the corresponding row in column L + 1.
    For example; Row 11. Death Note, G11 is "Completed" but Death Note is already present in the Rewatched table. So L3 should be updated +1.

    In both cases, delete the target row in the Rewatching table.

    Kind regards,

    Marco
    Attached Files Attached Files
    Last edited by Marco-Kun; 12-18-2011 at 06:03 PM.

  2. #2
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Move row to different table depending on cell value

    Anyone? I'm really stuck on this part. I tried searching for similar codes but all I find is move it from Sheet1 to Sheet2, and no tables involved.
    Like this code:

    Please Login or Register  to view this content.
    Source: http://en.allexperts.com/q/Excel-105...heet-based.htm

    Where do I need to start?

    Kind regards,

    Marco-Kun

  3. #3
    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: Move row to different table depending on cell value

    Hi Marco

    Try the code in the attached. Let me know of issues.
    Attached Files Attached Files
    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.

  4. #4
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Move row to different table depending on cell value

    Hello John,

    When I run the code, it does update the "Times re-watched" field +1 for double entries.

    It also creates a new column for the Rewatching table called "Column1", filled with "X" for some rows. Why does this happen?
    Also, the code reports: Methode Range of object_Global has failed.
    Please Login or Register  to view this content.
    Kind regards,

    Marco
    Last edited by Marco-Kun; 12-16-2011 at 08:58 PM.

  5. #5
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Move row to different table depending on cell value

    Hello John,

    I tested some more and I came to the following conclusion:
    I had to change the column name in the code to the Dutch version, or else it wouldn't work. I wasn't aware of what it did, firstly.
    Please Login or Register  to view this content.
    My last question still stands: It also creates a new column for the Rewatching table called "Column1", filled with "X" for some rows. Why does this happen? What does it exactly do?

    On another note, the code works, although one thing should be different. When a title is already present, it updates the value in Column L + 1. But it should also delete the original
    row in the Rewatching table after this.

    Thanks for all your help!

    Kind regards,

    Marco

  6. #6
    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: Move row to different table depending on cell value

    Hi Marco

    Working with Tables is different than working with data is a normal worksheet. I'm not expert on many things in VBA but Tables are one of my many shortcomings. Regarding this
    It also creates a new column for the Rewatching table called "Column1", filled with "X" for some rows. Why does this happen? What does it exactly do?
    I'll explain that as soon as I figure out this as I thought it did just that
    When a title is already present, it updates the value in Column L + 1. But it should also delete the original
    row in the Rewatching table after this.
    I'll get back to you...probably tomorrow. Keep this in your pocket
    I had to change the column name in the code to the Dutch version
    because you'll need to do that also with any updated code.

  7. #7
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Move row to different table depending on cell value

    Hello John,

    Thank you very much for your help. I'll wait for your return.
    I'm sure you are able to figure out why it doesn't work!

    I'll keep that in mind, thank you.
    On a side note, is it possible for this code to run as a Worksheet_Change event?
    Also, like last time, may I request for you to add notes for me to understand the code a little better?

    Thanks in advance,

    Marco

  8. #8
    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: Move row to different table depending on cell value

    Hi Marco

    This was my first thought when I read your original request
    is it possible for this code to run as a Worksheet_Change event
    I'd think that's the logical way for this to run and I'll pursue that avenue if/when we get the procedure to do as you require. As I mentioned, Tables are a different animal...baby steps first...get those working, we can explore bigger steps.

    Certainly...be happy to do this
    may I request for you to add notes for me to understand the code a little better
    I need to understand what's not working. You say this
    On another note, the code works, although one thing should be different. When a title is already present, it updates the value in Column L + 1. But it should also delete the original
    row in the Rewatching table after this.
    I thought the code was doing that...I'l look at the test file again and address this. In the meantime...is there anything else that's NOT working?

  9. #9
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Move row to different table depending on cell value

    Hi John,

    You are right. Solving the problems first should be the first priority.
    At the moment, no, I do not see anything else being wrong.
    I wanted to ask for you to add the function to order both tables alphabetically, but I got that to work already with the following code.

    Please Login or Register  to view this content.
    I added another file in which I try to show you what the code isn't doing by showing you how it looks like whenever the code is being used and how it should look.
    I hope the file helps you a bit!

    Thank you!

    Marco
    Attached Files Attached Files

  10. #10
    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: Move row to different table depending on cell value

    Hi Marco

    Please post the code (or a workbook that includes the code) that includes this
    Please Login or Register  to view this content.
    I'd like for us to be on the same page.

  11. #11
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Move row to different table depending on cell value

    Hello John,

    Of course. Below is the complete code. The part for alphabetical order is added on the bottom.
    Be aware that for the example sheet added in my previous post, this wasn't added.
    So I added another sheet with examples as attachment in this post, with below code added.
    It's easier to use this sheet because my example Tables had the alphabetical order code being used on.
    Be aware of the "Kolom1" in both the code and the sheet! Should be "Column1" for you.
    Please Login or Register  to view this content.
    Kind regards,

    Marco
    Attached Files Attached Files
    Last edited by Marco-Kun; 12-17-2011 at 10:04 AM.

  12. #12
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Move row to different table depending on cell value

    [REMOVED]Sorry for this post, was not supposed to reply here, but I have multiple tabs open...

    This post is totally clarified for deletion...
    Last edited by Marco-Kun; 12-17-2011 at 05:29 PM.

  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: Move row to different table depending on cell value

    Hi Marco
    What's your actual process in entering data in Rewatching. For example Column F (Left) becomes 0 by formula (Column D minus Column E). Then Column G (Status) becomes "Completed" when Column H (Status 2) is changed to "Finished Airing".

    So, it appears to me that the Change Event code will be fired by a change in Column H (Status 2). Is my thinking correct?

  14. #14
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Move row to different table depending on cell value

    Hello John,

    Do you want to know this for creating a Change Event code for moving the rows?
    You are right, but only if Column H doesn't have the value "Finished Airing" already.
    If it already has the value "Finished Airing", the Change Event code will be fired by a change in Column E (Watched Episodes). When this equals the number in Column D (Total Episodes), Column G (Status) will turn to "Completed".

    Kind regards,

    Marco
    Last edited by Marco-Kun; 12-17-2011 at 05:26 PM.

  15. #15
    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: Move row to different table depending on cell value

    Hi Marco
    This code is in the attached and appears to do as you require...let me know of issues.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  16. #16
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Move row to different table depending on cell value

    Hello John,

    Thank you very much! I'm looking into it right now. I'll test it some more. The Change Event code seems to work!
    For now I see two things:
    - It doesn't sort the tables alphabetically
    - When a row is moved from "Rewatched" to "Rewatching", the colour doesn't change anymore to the same as the titles in the "Rewatched" table (light blue). It stays orange like as they are in the "Rewatching" table.

    Thanks for all your great help!

    Kind regards,

    Marco

  17. #17
    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: Move row to different table depending on cell value

    Hi Marco
    You have the Sort Code from a previous Thread. Try to work it in...if you have issues with that let me know.
    This I'll look at (unless you want to fix it)
    the colour doesn't change anymore to the same as the titles in the "Rewatched" table (light blue).

  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: Move row to different table depending on cell value

    Hi Marco
    To fix this
    the colour doesn't change anymore to the same as the titles in the "Rewatched" table (light blue).
    add this line of code
    Please Login or Register  to view this content.
    here
    Please Login or Register  to view this content.
    Last edited by Paul; 12-18-2011 at 07:36 PM. Reason: fixed underline tag (wasn't surrounding line of code)

  19. #19
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Move row to different table depending on cell value

    Quote Originally Posted by jaslake View Post
    Hi Marco
    You have the Sort Code from a previous Thread. Try to work it in...if you have issues with that let me know.
    This I'll look at (unless you want to fix it)
    Hello John,

    I'll try to fix both these things myself.

    I added an example sheet. I had to put it in a .Zip file for some reason. Wouldn't upload as a normal .xls file.
    Quick explanation:
    This is My Anime list in which I keep track of all my anime shows I watch.

    MyAnimeList Sheet: This contains a table where all my anime shows are in. On the bottom is a button which can be used to add a new anime to the list.
    If you select a show in column A it shows a picture. There are only four entries now though, instead of 200+ on the first sheet.

    Rewatching Sheet: This sheet contains shows I currently rewatch. On the bottom is a button which shows the list from the MyAnimeList sheet. This is where your code comes in from this thread:
    http://www.excelforum.com/excel-prog...o-another.html

    It used to work, but now because of the Change Event code, it moves the row instantly to the Rewatched table, so it can't add more data.
    The button tries to add the data to the Rewatching table.

    Kind regards,

    Marco
    Attached Files Attached Files
    Last edited by Marco-Kun; 12-18-2011 at 04:53 PM. Reason: "I" instead of "It"

  20. #20
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Move row to different table depending on cell value

    Oh.. haha it seems I was too late!

    Thanks for the fix! I'm curious about why above problem happens....

    Kind regards,

    Marco
    Last edited by Marco-Kun; 12-18-2011 at 06:01 PM.

  21. #21
    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: Move row to different table depending on cell value

    Hi Marco
    The code in Module4 "Find_AnimeRewatch" fires the Change Event code because it CHANGES data in Columns 5 & 8 of Rewatching Table. Add this line of code at the top of "Find_AnimeRewatch" (just after the Dim Statements)
    Please Login or Register  to view this content.
    and add this line of code at the bottom of "Find_AnimeRewatch" (just before End Sub)
    Please Login or Register  to view this content.
    See if that works for you.

  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: Move row to different table depending on cell value

    Hi Marco...one point (so you don't get feedback from the Administrators)...please don't quote entire posts...quote only relevant data...Administrators get a bit exercised about that.

  23. #23
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Move row to different table depending on cell value

    Hello John,

    Thanks for the reminder. I removed the quote from my last post. Haha. I saw administrators talk about that a few times.

    About the code, that works perfectly! Now everything works great! Thank you very much, John!

    Kind regards,

    Marco
    Marked as [SOLVED]

  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: Move row to different table depending on cell value

    Hi Marco
    You're welcome...glad I could help.

+ 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