Move Rows With Different Tab Names - Dropdown

Поделиться
HTML-код
  • Опубликовано: 22 янв 2025

Комментарии • 94

  • @sheetswithsajid5158
    @sheetswithsajid5158 2 года назад

    If column C Heading "ARC,Caption" without dropdown from pasted through anther master sheet .how row shift anther sheet because here column C didnot edit.

    • @SpencerFarris
      @SpencerFarris  2 года назад

      I'm sorry, I don't understand the question

  • @starnovie-gc7vd
    @starnovie-gc7vd 9 месяцев назад

    hello! i used this for a google sheet i made for a watchlist, so once we see a movie on the list i wanted it to go to the watched tab, and that part works great! but i cannot figure out how to delete the range that was moved, it just leaves blank rows behind where i would want them to just disappear. hopefully this makes sense lol, the range i'm moving is (r.rowStart,1,5,13) so there are more rows than in your video that need to be deleted if that makes a difference

    • @SpencerFarris
      @SpencerFarris  9 месяцев назад

      Use deleteRows()
      developers.google.com/apps-script/reference/spreadsheet/sheet#deleteRows(Integer,Integer)

  • @kathrinablack7405
    @kathrinablack7405 2 года назад

    I've been trying this with my data sheet and I can't see to get it to work. I'm trying to move student data rows from the Master Data sheet to the Withdrawn sheet with a drop down menu using A (active) and w (withdraw). I don't think I am doing the code correctly.

  • @kgayken0121
    @kgayken0121 Год назад

    Hey Spencer - I am having issues with my Open Tab. When I move something from Open to closed it goes to the top of the page, but if I move it from Closed to Open it automatically goes to the bottom of the page
    const valArray = ["Open","Waitlist","Closed","PM"];
    const destArray = ["WOs","Waitlist","Closed","PMs"];
    let dest = sh.getSheetByName(destArray[valArray.indexOf(e.value)]);
    let src = sh.getActiveSheet();
    if (dest.getName() == src.getName()) return;
    src.getRange(r.rowStart,1,1,8).moveTo(dest.getRange(dest.getLastRow()+1,1,1,8));
    src.deleteRow(r.rowStart);
    }

    • @SpencerFarris
      @SpencerFarris  2 месяца назад

      Sorry it's been SO LONG. Do you still need help?

  • @mauryhernandez2297
    @mauryhernandez2297 Год назад

    For some reason the script forces me to leave the sheet, and I know it could be caused due a big amount of rows, however, the script is currently working perfectly with another bigger sheet... why is that??

    • @mauryhernandez2297
      @mauryhernandez2297 Год назад

      const VAL_ARRAY = ["Remove","READY TO INVOICE","COLLECTED","ARCHIVE"];
      const DEST_ARRAY = ["DEFLEETED","INVOICED","ARCHIVE","ARCHIVE"];
      const ss = SpreadsheetApp.getActive();
      const sheets = {};
      for (let i = 0; i < DEST_ARRAY.length; i++) {
      sheets[DEST_ARRAY[i]] = ss.getSheetByName(DEST_ARRAY[i]);
      }
      function onEdit(e) {
      const r = e.range;
      if (r.columnStart !== 24 || r.rowStart === 1 || e.value == null) return;
      const dest = sheets[DEST_ARRAY[VAL_ARRAY.indexOf(e.value)]];
      const src = r.getSheet();
      if (dest.getName() === src.getName()) return;
      const data = src.getRange(r.rowStart, 1, 1, 25).getDisplayValues();
      dest.getRange(dest.getLastRow() + 1, 1, 1, 25).setValues(data);
      src.deleteRow(r.rowStart);
      }

    • @SpencerFarris
      @SpencerFarris  Год назад

      Sorry, what do you mean "forces me to leave the sheet?"

  • @knottaustin92
    @knottaustin92 2 года назад

    Hey Spencer,
    If I wanted to move this row and either the one above or below it utilizing just the one drop down. So I guess they would be linked in some way.
    how would I go about that. Ive got this working as is thanks to you but am needing to group rows together.

    • @SpencerFarris
      @SpencerFarris  2 года назад

      You would just change the number_of_rows parameter of getRange() from 1 to 2.

  • @Troy-ii5vj
    @Troy-ii5vj 10 месяцев назад

    Hi Spencer! thanks again for all these amazing videos. I could use a little help though. I am trying to run the script but I can only get it to partially work. I need "Active" and "Inactive" from a dropdown to both go the the "Contacts" sheet. My Graveyard to the Graveyard sheet works correctly though. Any advice? I also don't know if it's an issue that that data to sort in contacts doesn't start until row 16.
    I know this is wrong but it's to give an idea
    function onEdit(e){
    let r = e.range;
    if (r.columnStart != 1 || r.rowStart == 1 || e.value == null) return;
    const sh = SpreadsheetApp.getActive();
    const valArray = ["Active","Inactive","Graveyard"];
    const destArray = ["Contacts","Contacts","Graveyard"];
    let dest = sh.getSheetByName(destArray[valArray.indexOf(e.value)]);
    let src = sh.getActiveSheet();
    if (dest.getName() == src.getName()) return;
    src.getRange(r.rowStart,1,1,10).copyTo(dest.getRange(dest.getLastRow()+1,1,1,10));
    src.getRange(r.rowStart,1,1,10).clearContent();
    }

    • @Troy-ii5vj
      @Troy-ii5vj 10 месяцев назад

      NVM. I solved it using
      /*
      @OnlyCurrentDoc
      */
      let tabs = {
      'Active':'Contacts',
      'Inactive':'Contacts',
      'Graveyard':'Graveyard'
      }
      function onEdit(e){
      let r = e.range;
      let val = r.getValue();
      if (r.columnStart != 1 || r.rowStart == 1 || e.value == null) return;
      const sh = SpreadsheetApp.getActive();
      let dest = sh.getSheetByName(tabs[val]);
      let src = sh.getActiveSheet();
      if (dest.getName() == src.getName()) return;
      src.getRange(r.rowStart,1,1,10).copyTo(dest.getRange(dest.getLastRow()+1,1,1,10));
      src.getRange(r.rowStart,1,1,10).clearContent();
      }

    • @SpencerFarris
      @SpencerFarris  9 месяцев назад

      I love seeing people learn and solve

  • @caitlyncarter6915
    @caitlyncarter6915 2 года назад

    I have followed this to a T and this is not working for me. I have not coded in about 8 years and im working on something for my company and i can not seem to get this code to work can you help?

    • @SpencerFarris
      @SpencerFarris  2 года назад

      Can you add me as an editor? spencer.farris@gmail.com

  • @danielautoechipat3938
    @danielautoechipat3938 3 года назад

    Hello. How can i move row ignorig the formula as last row? It move to another sheet but put data after the formula not after the last row.

    • @SpencerFarris
      @SpencerFarris  3 года назад

      It's doing exactly what it's supposed to - ss.getLastRow() gets the absolute last row with any data, it doesn't know that you have a formula that you want to move down. You'll need to insert a row after the penultimate row then move the data there.

    • @danielautoechipat3938
      @danielautoechipat3938 3 года назад

      @@SpencerFarris Thanks for answering so quickly. Here an example of my problem:
      docs.google.com/spreadsheets/d/1qowADCPYiyej25ezXtjVLO5fvg9Gr9rolX3bh2-ZAG4/edit?usp=sharing

  • @elenab638
    @elenab638 2 года назад

    Hi, ty for this video. May I ask you how can i do if i wanna share a sheet with this automation and I wanna make the automation working also for the others editors of the sheet?

    • @SpencerFarris
      @SpencerFarris  2 года назад +1

      Since this is a simple onEdit trigger it should work for all users.

  • @Jack-fx2jf
    @Jack-fx2jf 2 года назад

    My drop down has an extra 12 columns after it. How do I get those to also move over to a different sheet?

    • @SpencerFarris
      @SpencerFarris  2 года назад

      The .getRange() method takes (start_row, start_column, number_of_rows, number_of_columns) so you can just adjust the number_of_columns

    • @Jack-fx2jf
      @Jack-fx2jf 2 года назад

      @@SpencerFarris Thanks for the reply mate! Another quick question. So in the column before the drop down I have another drop down/ Both of these are colour coded for each value. For some reason when the trigger column is changed it also changes the colour of the column next to it. Any ideas? Thanks :)

    • @SpencerFarris
      @SpencerFarris  2 года назад

      @@Jack-fx2jf Not sure, I'd need to see the sheet/code

  • @auxineblairepahilmagan5022
    @auxineblairepahilmagan5022 3 года назад

    Hi Spencer, I am try to move data to another sheets and it works but it keeps moving 2 rows to my target sheet.

    • @SpencerFarris
      @SpencerFarris  3 года назад

      please add me as an editor to the Sheet

  • @nidhi0588
    @nidhi0588 Год назад

    Hi Spencer, thank you for making this video. I spent hours looking for this. but unfortunately it is not working for me. it doesn't do anything for me. can you please help? I wanted to use this on my workload management sheet for my team. when they click on complete it should go to another tab in the same sheet. I was able to copy it automatically using filter but I want to move it to different tab. let me know if you want me to share the sheet with you. thank you!

    • @SpencerFarris
      @SpencerFarris  2 месяца назад

      Sorry it's been SO LONG. Do you still need help with this?

  • @TheKawasaki500s
    @TheKawasaki500s 3 года назад

    Is there a similar macro code for excel instead of google sheets, I love what it does but I'm trying to do something similar in excel

    • @SpencerFarris
      @SpencerFarris  3 года назад +1

      I'm sure there is, but I abandoned Excel years ago. I used to do quite a bit of VBA, but haven't been involved there in a while. You can check out StackOverflow, Reddit, excelforums, or Discord for help

    • @TheKawasaki500s
      @TheKawasaki500s 3 года назад

      @@SpencerFarris thank you

  • @tamirizhak1453
    @tamirizhak1453 2 года назад

    Hey Spencer - thank you for this video.
    I'm trying to figure out how to do the same only that I have some merged rows to move.
    I thought about using row groups on the merged rows so that I can identify the row range to be move and use it in the getrange method - but no entirely sure if it's possible.
    Hope you can help me out.

    • @SpencerFarris
      @SpencerFarris  2 года назад

      Merged rows should work normally without issue

  • @nextlevel8991
    @nextlevel8991 2 года назад

    Hey Spencer - Thank you for this video.
    I have tried your code and it works fine. but I need to set column dynamically. like:
    const numColumns = r.getLastColumn();
    this instead of setting column length. Please help me to use const numColumns = r.getLastColumn();

    • @SpencerFarris
      @SpencerFarris  2 года назад

      I'm sorry, it's unclear to me what you want. Can you please add me as an editor on the sheet? spencer.farris@gmail.com

  • @hg7791
    @hg7791 2 года назад

    Hello Spencer, great video.
    It is working perfectly however, I have a 7 column table and it doesn't move all of them. It just moves the fisrt 3 columns int the row. I would appreciate your help, thank you.

    • @SpencerFarris
      @SpencerFarris  2 года назад

      The parameters of .getRange are (start_row,start_column,number_of_rows,number_of_columns). In my code I have number_of_columns set to 3. Change that to 7 and it should work.

    • @hg7791
      @hg7791 2 года назад

      @@SpencerFarris You saved me. Thanks a lot!

  • @sujalpatel4599
    @sujalpatel4599 Год назад

    Hello Spencer firstly great video glad i came Across this.
    I have a question how would i make it so that on edit it only goes to one sheet?

    • @SpencerFarris
      @SpencerFarris  Год назад

      What do you mean "only goes to one sheet?" Is it going to more?

  • @josuecenteno731
    @josuecenteno731 2 года назад

    Hello Spencer, hope you are doing good.
    I would like to ask you how to move only once cell to another tab using the dropdown option.
    I learned with you how to move the entire row but I would like to move only one cell to another tab.

    • @SpencerFarris
      @SpencerFarris  2 года назад

      You would just do something like e.range.moveTo(dest.getRange(dest.getLastRow()+1,1))

  • @macmoulson
    @macmoulson Год назад

    Hi Spencer, this tutorial has been a life saver. I just have one question about the output of information. Is there a way once we get the range to only transfer over certain row information. For instance if we get the range src.getRange(r.rowStart,1,1,9) is there a way to only output the info in columns A, B, C, H, and I to the new sheet?

    • @SpencerFarris
      @SpencerFarris  Год назад

      let vals = src.getRange(r.rowStart,1,1,9).getValues();
      let indices = [0,1,2,6];
      let outVals = indicies.map(i => vals[i]);
      dest.getRange(dest.getLastRow()+1,1,1,4).setValues(outVals);

  • @jodie-louisetheyer395
    @jodie-louisetheyer395 2 года назад

    Hello, similar to a response below I am also finding that this isn't happening automatically. Did you manage to find out their problem?

    • @SpencerFarris
      @SpencerFarris  2 года назад

      I don't know which response you're referring to, sorry.
      I'm happy to look at your sheet and see what's going on, though.

    • @jodie-louisetheyer395
      @jodie-louisetheyer395 2 года назад

      @@SpencerFarris I think I have found the error - The data in the sheet is coming from a google form. If I manually enter a line the script will work but any data pulled through from the form won't. Do you know if it is possible to make it work with the google form responses?

    • @SpencerFarris
      @SpencerFarris  2 года назад

      @@jodie-louisetheyer395 Is the column/value being populated by the form, or is it not moving the row created by the form when you enter data manually?

    • @jodie-louisetheyer395
      @jodie-louisetheyer395 2 года назад

      @@SpencerFarris the form populates a row of data, leaving column 1 empty. Column 1 gets manually updated based on whether is task is new, in progress or resolved. If I change this cell to resolved the row doesn't move to the resolved tab. However if I manually enter a full row of data and then change the first column to resolved this will move the full row to the correct tab.

    • @jodie-louisetheyer395
      @jodie-louisetheyer395 2 года назад +1

      I've managed to resolve this by using an array forumla to copy the form responses into a new tab & then run the script from there instead. I'm not sure if this is correct way but it does also enable me to format the data. Thank you so much for your tutorial & responses!

  • @farkhadhuseinov5246
    @farkhadhuseinov5246 2 года назад

    Code occured an error as: 4:09:36 PM Error
    TypeError: Cannot read property 'range' of undefined
    onEdit @ Code.gs:2

    • @farkhadhuseinov5246
      @farkhadhuseinov5246 2 года назад

      function onEdit(e){
      let r = e.range;
      if (r.columnStart != 22 || r.rowStart == 1 || e.value == null) return;
      const sh = SpreadsheetApp.getActive();
      const valArray = ["Approved","Not approved"];
      const destArray = ["Complete","QAC"];
      let dest = sh.getSheetByName(destArray[valArray.indexOf(e.value)]);
      let src = sh.getActiveSheet();
      if (dest.getName() == src.getName()) return;
      src.getRange(r.rowStart,1,1,22).moveTo(dest.getRange(dest.getLastRow()+1,1,1,22));
      src.deleteRow(r.rowStart);
      }

    • @SpencerFarris
      @SpencerFarris  2 года назад

      Don't run the script - it runs automatically when an edit is made and needs the data from the 'e' to work.

    • @farkhadhuseinov5246
      @farkhadhuseinov5246 2 года назад

      @@SpencerFarris unfortunately it doesn't work automatically why?

    • @SpencerFarris
      @SpencerFarris  2 года назад

      @@farkhadhuseinov5246 No idea. Can you add me as an editor?

    • @farkhadhuseinov5246
      @farkhadhuseinov5246 2 года назад

      @@SpencerFarris gave you access

  • @Jack-fx2jf
    @Jack-fx2jf 2 года назад

    Hey! Me again haha. Is there a way to get the row that's moving to a new sheet to always go to the 2nd row on the different tab instead of becoming the last row in the table? I thought it would have something to do with this line of script:
    src.getRange(r.rowStart,1,1,10).moveTo(dest.getRange(dest.getLastRow()+1,1,1,10));
    but not entirely sure what to edit

    • @SpencerFarris
      @SpencerFarris  2 месяца назад

      Sorry it's been SO LONG. Do you still need help?

  • @elizabethmacmahon6241
    @elizabethmacmahon6241 2 года назад

    Hi Spencer, this is a great video. How do you move rows if you don't want them to automatically go to the last row of the new sheet?

    • @SpencerFarris
      @SpencerFarris  2 года назад +1

      Where do you want them to go?

    • @elizabethmacmahon6241
      @elizabethmacmahon6241 2 года назад

      @@SpencerFarris thank you very much for your reply! I want the rows to go to the other sheet based on a specific column name (and it could go under the last row that has that specified column). Hope that makes sense. Is it possible to get your email? Or maybe what I wrote is enough.

    • @elizabethmacmahon6241
      @elizabethmacmahon6241 2 года назад

      For instance, say if I were moving tasks based on a drop down (in progress, done, etc.) and want to move them to the next sheet under the last row that has column name, Chicago or New York

    • @SpencerFarris
      @SpencerFarris  2 года назад

      @@elizabethmacmahon6241 spencer.farris@gmail.com (it's in the video description)

    • @peterzahran5451
      @peterzahran5451 2 года назад

      @@SpencerFarris Thanks for the great work! Could the row be moved to the first available row instead? In my case, it would be row 2 under the column headings.

  • @dethered86
    @dethered86 2 года назад

    Spencer, Thank you for this! I do have a question though. Is there a way to delete the values only from the main sheet? My main sheet is a project log and when I drop down and select "completed" it does exactly what I want but if I want to add something in its place on the main sheet I have to recreate all of the formatting, colors, data validation, drop down menus, etc. Thanks so much for your help!

    • @SpencerFarris
      @SpencerFarris  2 года назад

      Try using
      src.getRange(r.rowStart,1,1,3).copyTo(dest.getRange(dest.getLastRow()+1,1,1,3));
      src.getRange(r.rowStart,1,1,3).clearContent()

  • @mauryhernandez2297
    @mauryhernandez2297 2 года назад

    Do you have a script to do this... by the way, this is beautiful... anyways, do this, but it also can be done from two different columns?? I mean, can the trigger be done in two separate columns?

    • @SpencerFarris
      @SpencerFarris  2 года назад

      if ((r.columnStart != 3 && r.columnStart != 7) || r.rowStart == 1 || e.value == null) return;

  • @Orcadreams33
    @Orcadreams33 2 года назад

    Hi Spencer, me again! Thank you so much for directing me to this video, you are great help! It's now working perfectly, except that it takes 2 rows instead of 1, the one I am wanting and then the one below it. I am wondering if there is something I can do to stop this? Any help is much appreciated!

    • @SpencerFarris
      @SpencerFarris  2 года назад

      Did you create a trigger?

    • @Orcadreams33
      @Orcadreams33 2 года назад

      @@SpencerFarris Yes I have an OnEdit trigger in place!

    • @SpencerFarris
      @SpencerFarris  2 года назад +1

      @@Orcadreams33 Delete that. Naming a function "onEdit" is what is called a "simple trigger." By having the named simple trigger and the installed trigger it's running twice.

  • @ridrajas
    @ridrajas 2 года назад

    Thank you so much my dear favorite sir🥰🥰💚💚💚💚

  • @socomau21
    @socomau21 2 года назад

    How to do this but not deleting from the first tab… Just sending copies to other tabs…

    • @SpencerFarris
      @SpencerFarris  2 года назад

      Change .moveTo to .copyTo and remove the .deleteRow call

  • @ZabuArts
    @ZabuArts 2 года назад

    Really great! Thanx man 💪💪

  • @sheetswithsajid5158
    @sheetswithsajid5158 2 года назад

    very amazing and useful. thanks thanks thanks😊

  • @DeanONeill-gp4cl
    @DeanONeill-gp4cl 2 года назад

    HI Spencer - thanks a mill on this video its really helped my a lot.
    i have been working with this for a few months now and its been going great.
    i only have one problem, ive been trying to load it on a new sheet but i keep getting TypeError : Cannot read properties of undefined (reading 'range' ) onEdit @ Code.gs:2
    please help

    • @SpencerFarris
      @SpencerFarris  2 месяца назад

      Don't run the script. It runs automatically whenever an edit occurs and needs information from the edit to function