Тёмный

Move Rows of Data in Google Sheets - Apps Script Tutorial 

Sheets Ninja
Подписаться 2,1 тыс.
Просмотров 22 тыс.
50% 1

In this video, I quickly demonstrate and explain how to put together a Google Sheet and the App Script to be able to quickly move rows of data between tabs using a dropdown status.
If you want to make a copy of the Google Sheet and script I used in the video, check it out here: bit.ly/3Bd67bY
If you just want to move the data up or down to a different section in the sheet, check out this video: • Move Row Between Secti...
If you're ready to take it to the next level, check out Part 2 here: • Move Rows of Data in G...
If you need to move both formulas and data, check out this video: • Video
If you're looking at moving multiple rows of data at once, check out this video: • Moving Multiple Rows o...
If you want to move a row of data to a completely different spreadsheet, check out this video: • Move A Row to Differen...

Опубликовано:

 

12 сен 2022

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 191   
@toflof8407
@toflof8407 5 месяцев назад
This is exactly what I've been searching for. Thanks so much for sharing your knowledge.
@SheetsNinja
@SheetsNinja 5 месяцев назад
Awesome, so glad this was helpful for you! Glad to share.
@michaelnotarte4424
@michaelnotarte4424 Год назад
+ 1 like and + 1 subscriber. You made everything look so simple. Well done!
@SheetsNinja
@SheetsNinja Год назад
Awesome, thank you!
@HJonesT
@HJonesT 7 месяцев назад
This is great, super close to what I was trying to do. Now to brush up so I can make the edits I need, haha.
@SheetsNinja
@SheetsNinja 7 месяцев назад
Awesome!
@frankdetkos9463
@frankdetkos9463 Год назад
HUGE time saver for work!
@SheetsNinja
@SheetsNinja Год назад
Awesome, glad this was helpful!
@gabrielsguerreiro13
@gabrielsguerreiro13 Год назад
Thanks.. i was looking for that solution a long time .. great job👏👏😃😅
@SheetsNinja
@SheetsNinja Год назад
Happy to help
@MelissaWaters-xq1sj
@MelissaWaters-xq1sj Месяц назад
So helpful and easy to follow--thanks.
@SheetsNinja
@SheetsNinja Месяц назад
Awesome, so glad this was helpful for you!
@aab_jbriones
@aab_jbriones 2 месяца назад
L-O-V-E THIS! Thank you so much!!!
@SheetsNinja
@SheetsNinja 2 месяца назад
Awesome, so glad this was helpful! Check out our other videos for more tutorials on all kinds of stuff!
@SJUS-uw8bg
@SJUS-uw8bg 10 месяцев назад
This is exactly what i needed it for, thank god
@SheetsNinja
@SheetsNinja 10 месяцев назад
Awesome, so glad it was helpful!
@SJUS-uw8bg
@SJUS-uw8bg 10 месяцев назад
@@SheetsNinja What can i add to the code to make the script ignore Sheet 1 for example? This is the last bit i need to make my pipeline work, because this is my master sheet where all the data needs to go
@SheetsNinja
@SheetsNinja 10 месяцев назад
I have other videos linked in the description that go deeper into this and give examples, but essentially you wrap the rest of the function in an if condition that excludes the first tab.@@SJUS-uw8bg
@mikedavis528
@mikedavis528 Год назад
Hey Ninja, I'm trying to set up multiple charts on the same sheet side by side with their own drop downs. I've figured out how to change the script to grab just the info from the selected chart (For instance if I have 3 charts side by side and I select a drop down for the middle one) however it copies it onto the destination sheet in the first available slots (The left chart instead of staying in the the middle chart). I also can not get just the info from one chart to delete after moving, it still wants to delete the entire row. Please help if you can! Much appreciated thank you!
@D3YTV
@D3YTV 3 месяца назад
Big help! Thanks!!
@SheetsNinja
@SheetsNinja 3 месяца назад
Awesome, so glad this was helpful!
@DreamShare.Studio
@DreamShare.Studio 11 месяцев назад
Thank you, this is very helpful! You have a new subscriber. One question, if I want to clear the transferred row instead of delete it, what is the proper modification to the code?
@SheetsNinja
@SheetsNinja 11 месяцев назад
Copy the row of code that ends with ".getValues()", paste it below, and then replace ".getValues()" on that new line with ".clearContent()", then make sure to delete the row with "sheet.deleteRow()".
@L3G1T23
@L3G1T23 10 месяцев назад
Thanks so much for putting this together!! Can you help with what I would need in order to make this work where the row only moves if two conditions are met? I don't want a row to move to a different sheet unless two or three cells have specific values.
@SheetsNinja
@SheetsNinja 10 месяцев назад
I just added a video covering using multiple criteria: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-KekdeXn8P5Y.html
@romand.lopeztovar552
@romand.lopeztovar552 17 дней назад
This is awesome, thanks!!!!
@SheetsNinja
@SheetsNinja 17 дней назад
Just doing my job of spreading awesomeness! Stay tuned for more!
@1stMoonLover
@1stMoonLover 10 месяцев назад
Thank you so much sir 😊
@SheetsNinja
@SheetsNinja 10 месяцев назад
Glad it was helpful!
@nearemus
@nearemus 27 дней назад
Thanks, I've subbed
@SheetsNinja
@SheetsNinja 27 дней назад
Glad this was helpful, thank you and see you around!
@puneetgupta2000
@puneetgupta2000 2 месяца назад
Thank you very much!
@SheetsNinja
@SheetsNinja 2 месяца назад
You're welcome! Glad it was helpful!
@JT-hx4hz
@JT-hx4hz Год назад
Extremely helpful. What additions to the script would be needed to have formulas in the row be able to mover over as well?
@SheetsNinja
@SheetsNinja Год назад
So you can move formulas with the .getFormulas() method and .setFormulas() method, and you use it just like .getValues() and .setValues()
@JT-hx4hz
@JT-hx4hz Год назад
@@SheetsNinja I appreciate the quick response. I'm entirely new to all of this so I'm unsure how to implement .getFormulas() or .setFormulas() within the script you have written in the video.
@SheetsNinja
@SheetsNinja 10 месяцев назад
I created a new video showing how to copy formulas: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-i2VgEclS4ps.html
@user-gd5cw1xp9w
@user-gd5cw1xp9w 11 месяцев назад
Hey, Thanks for this. I have a sheet that in the status columnin sequence moves through 4 tabs and then it’s finished with. However on tab 3 it would depend on status and another answer on column F drop down. So if Status = complete and column F was blank it goes to the complete tab. If column F Said YES it would copy the row to 2x other tabs but also delete from the current tab
@SheetsNinja
@SheetsNinja 10 месяцев назад
I just created a new video showing how to use multiple criteria: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-KekdeXn8P5Y.html Combined with my part 2 to this video, that will explain all the concepts needed to complete your project: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-0Up8bqnfttA.html
@THOLOGHANZI
@THOLOGHANZI 21 день назад
Thank you so much for this video. I do have a question - how will I use this App script on a google sheet that have protected ranges in it? Will it still work?
@SheetsNinja
@SheetsNinja 21 день назад
If there are protected ranges that are warning only, this will still work. If it prevents people from editing, then you will need to make sure you use an installed trigger and that the user who installs the trigger has edit access everywhere the script will need access.
@jaysonancajas9200
@jaysonancajas9200 Год назад
Awesome ! Can you make another case. To automatically delete entire row once the one cell has been delete?
@SheetsNinja
@SheetsNinja Год назад
This would be tricky, detecting a deleted cell isn't always reliable, it's better to use a checkbox or a dropdown to trigger deleting a row.
@SuperRajan05
@SuperRajan05 Год назад
Hey Thank you for this amazing tutorial, I am using the Query (importrange) function to acquire data on my sheet, now when i am using this script, it is making a copy of the row instead of moving it. Is there anything that can be done to rectify that?
@SheetsNinja
@SheetsNinja Год назад
So you can't move data when you're using importrange, because the data is just being displayed in those cells. You could potentially use a filter formula to exclude any data from showing up there that you're copied to another tab.
@katiehelander170
@katiehelander170 Год назад
I've been trying this formula but when I execute it, it deletes both the correct row and the one underneath it. I have the exact script you used pasted into Apps Script, so not sure what the problem is
@helenchen2907
@helenchen2907 Год назад
That's an awesome table ... where did you learn about this? I am really interested in it...
@SheetsNinja
@SheetsNinja Год назад
Lots of trial and error, reading apps script documentation, watching RU-vid videos, and taking Javascript tutorials.
@user-ln3ps7df9n
@user-ln3ps7df9n 9 месяцев назад
Hi Ninja, This worked great for me. I need to add something into this, do you mind helping me? I want the data to remain on the original sheet when moving it over to another tab. But when on the tab, if it then moved to another tab, I want it to be removed from there. So When I move the status to "Prospect" it is copied there. But when I move the status from Prospect to "Sales" it remains in both prospect and sales. I want it to be removed from prospect, but remain always in "Lead" Thanks.
@SheetsNinja
@SheetsNinja 9 месяцев назад
You just have to wrap the line "sheet.deleteRow(row)" like this: if (source.getName() == "Prospect") { sheet.deleteRow(row); } That will only delete the data when the data is getting moved from Prospect to another tab. You can wrap any other tab-specific logic in an if statement like this.
@forcenick
@forcenick Год назад
This is awesome, where did you learn to create apps script?
@SheetsNinja
@SheetsNinja Год назад
I've been building Google Sheets full-time for 2 years now, so it's been on-the-job learning. Many late nights and lots of frustration!
@rabinchaudhary258
@rabinchaudhary258 Год назад
Thank you so much for the Awsome & very helpful vdo... Can u plz help me, one more thing when I create google form in the same format and I used this code then it's working or not ???
@SheetsNinja
@SheetsNinja Год назад
So when Google Form adds a response, it will not make the "onEdit" trigger run. You would need to use the "On form Response" trigger and then scan the last row for whatever condition you're looking for
@Jake-wc8fy
@Jake-wc8fy Год назад
This has worked great, my only struggle is that when i move the row it leaves behind the notes that where in a cell and the links linked to a work or number set
@SheetsNinja
@SheetsNinja Год назад
So before you delete the row, you can copy the .getValues() and .setValues() rows and change those additional rows to .getNotes() and .setNotes() If you're using smart chips, unfortunately I do not think apps script supports grabbing the data from those yet, but I'm expecting they will soon.
@kevinburger880
@kevinburger880 11 месяцев назад
Thanks for the help here- How can I move a row down to the bottom based on the results of a drop down? I have Paid and Unpaid invoices and want to move all unpaid rows to the bottom of the tab I am working on?
@SheetsNinja
@SheetsNinja 11 месяцев назад
Hey, so you can use the same logic but instead of the target being a different sheet, use the same sheet, so everything would be the same except for that line.
@Troy-ii5vj
@Troy-ii5vj 2 месяца назад
Thanks a lot for the super helpful video! I do have a question though. Is it possible to move a row from one group to another on the same tab after a box is checked?
@SheetsNinja
@SheetsNinja 2 месяца назад
That is definitely possible to do but can be tricky! For example, if you have a section for Pending, Sold, and Cancelled on that tab, I would put the section header text for those sections in column A for example, and have the rest of the the data starting in column B. Then assuming the status drop-down is on column B, I'd have the script then pull the values from column A and use index of to figure out what row those section headers are in, and then use .insertRow() method to add a new row in that section and then paste the data. Depending on your comfort level with scripts, that may sound intimidating, but I did add your project to my list of videos to make in the future.
@SheetsNinja
@SheetsNinja 2 месяца назад
I just recorded that video today! ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-HJlpzGvzw30.html
@rendraridhohaqiqi9226
@rendraridhohaqiqi9226 Год назад
thanks for the tutorial, how do you move to another worksheet? did try with oneedit(e) function but failed
@SheetsNinja
@SheetsNinja Год назад
So make sure you do not have @OnlyCurrentDoc in your script, secondly, for the target sheet, you need to do let targetSS = SpreadsheetApp.OpenById("target_sheet_id"); let targetSheet = targetSS.getSheetByName('targetTab'); And then you can use targetSheet for the .setValues() method
@beatrizjannmaglanoc8458
@beatrizjannmaglanoc8458 5 месяцев назад
awesome video! just wondering what if my column b is a hyperlink? would that affect the code?
@SheetsNinja
@SheetsNinja 5 месяцев назад
You'll just need to swap out .getValues() for .getRichTextValues() and .setValues(data) for .setRichTextValues(data).
@JulianaAristizabal-lq6rc
@JulianaAristizabal-lq6rc 2 месяца назад
Hi Sheets Ninja!! I managed to follow your tutorial and it works nicely! Thank you so much for the useful information. I have a question, completed projects are being moved from one tab to another when the status changes to 'completed', but can I make it so that once they've been moved to the other tab, I can move them back to the previous one using the same column? But by selecting a different state? This is the current script I am using, but is only working for moving to the first tab to the second one, not the other way when I need to. Thank you in advance! :) function onEdit(e){ let range = e.range; let col = range.getColumn(); let row = range.getRow(); let val = range.getValue(); let source = e.source.getActiveSheet(); if (col == 1 && val != ''){ let ss = SpreadsheetApp.getActiveSpreadsheet(); let sheet = ss.getSheetByName(source.getName()); let targetSheet = ss.getSheetByName(val); let data = sheet.getRange(row,1,1,sheet.getLastColumn()).getValues(); data[0][0] = ''; targetSheet.appendRow(data[0]); let formulas = sheet.getRange(row,1,1,sheet.getLastColumn()).getFormulasR1C1(); for (i=0;i
@SheetsNinja
@SheetsNinja 2 месяца назад
So if you have the name of the original tab in the dropdown then you can use the script as is, otherwise you will want to add a section in there to check if it's that tab name. For example, if the original tab is called "Active Projects" and you have a dropdown selection called "Back to Active" then you could do something like this: if (val == "Back to Active") { let targetSheet = ss.getSheetByName('Active Projects"); targetSheet.appendRow(data[0]); }
@yourface2616
@yourface2616 Год назад
Love it I used it on my google sheet but i have a form linked and google form overrides the script. Any suggestions?
@SheetsNinja
@SheetsNinja Год назад
So you can't copy data into a tab where Google Form is dumping responses. Best practice is to use another tab for your process.
@juliamoorehead8884
@juliamoorehead8884 Год назад
This would be a huge help for my workflow but after following all the steps for some reason it’s not working when I change the status drop down. My drop-down and tab names are different but since there is not specifics verbiage about “prospects” etc I figured as long as the drop down names correspond to the tab names It would work. Please let me know if you have any ideas why this might not be working for me
@SheetsNinja
@SheetsNinja Год назад
So the simplest solution is to make the dropdowns match the tab names exactly. If that's not possible, then you would have to add more in the script to handle the difference (e.g. "if (val == 'Prospects') { let tab = ss.getSheetByName('Prospects Tab'); } )
@jongreen2432
@jongreen2432 Год назад
Hey Ninja, thanks for the video. I used your script exactly and Im having an issue with the data jumping to the bottom of the new tab. Any advice?
@SheetsNinja
@SheetsNinja Год назад
So that is because there is something on the tab that doesn't look like blank rows to the script. Common things that cause that is checkboxes or formulas that have blank spaces as part of the formula (e.g. something like =IF(A2="","",rest_of_formula). The "" will still read as a row containing data for the script.
@jongreen2432
@jongreen2432 Год назад
You were right, I had a sum function in there. When removed it jumped to to the top. Thanks!
@PredragJokic
@PredragJokic Год назад
Hello and thank you for sharing th knowledge. If I May ask is there à way to check that all the cells in row are filled prior to send date to another sheet ? Thank in advance for your reply
@SheetsNinja
@SheetsNinja Год назад
You'll need to layer in an if statement with probably a for statement to loop through that row. For example: let ss = SpreadsheetApp.getActiveSpreadsheet(); let rowData = valuesFromRow: let check = true; for (i=0;i
@PredragJokic
@PredragJokic Год назад
Thank you for the reply I found à way. How cours one handle this when data get filled in from webapp. I made on but still need to reconfirm from dropdown in order to make it work. Is there a workaround in order to copy data automatically to coresponding sheet?
@ankitashastri4101
@ankitashastri4101 Год назад
Thank you so much , this is awesome .. it worked great..you got one subscriber........ just one question that I have put =Sequence(counta(B:B)) in A2, and as soon as I select the option in last column 17 the whole row get deleted and move to target sheet ... and with it my sequence formula also get deleted.. so what changes do i need to make in app script.. to keep that formula in place.. or the script don't delete the first column A? A prompt response will be much appreciated..
@ankitashastri4101
@ankitashastri4101 Год назад
one more thing the rows that are moving to new sheet is leaving so many rows blank up , why is that happening??
@SheetsNinja
@SheetsNinja Год назад
So you can put formulas in the header like so: ={"Column A Title";sequence(counta(B:B))}
@SheetsNinja
@SheetsNinja Год назад
@@ankitashastri4101 So this will happen if you have something in the target sheet that the apps script will read as a non-blank cell--for example, checkboxes, or a formula that you've already dragged down in other columns.
@ankitashastri4101
@ankitashastri4101 Год назад
@@SheetsNinja Thank you for the replies, will try for sure 🙏
@teresavasquez-williams1697
@teresavasquez-williams1697 4 месяца назад
Thanks for sharing this solution. I tried it and it worked for me, the only thing is every time I selected the tab name from the status column, the row moved to the proper tab, but it was not in row 1 instead it was in the last row, row 1000. How can I changed that?
@SheetsNinja
@SheetsNinja 4 месяца назад
Usually that is because you have check boxes in your target tabs. The simplest solution is to delete the checkboxes and have the script add them. Say the checkboxes are in column E, you can add this code to the script after it pastes the data: targetSheet.getRange(targetSheet.getLastRow(),5).insert checkboxes()
@user-cd9ok2rv5y
@user-cd9ok2rv5y 7 месяцев назад
Thank you so much for this video. Everything works perfect for me, however, I would like the rows with a status change added to the top of the new sheet rather than the bottom. Is this possible?
@dnlcollins
@dnlcollins 7 месяцев назад
I am also wondering this!
@SheetsNinja
@SheetsNinja 7 месяцев назад
So here's the updated code that will add the new rows to the top instead of the bottom: /* @OnlyCurrentDoc */ function onEdit(e){ let range = e.range; let col = range.getColumn(); let row = range.getRow(); let val = range.getValue(); let source = e.source.getActiveSheet(); if (col == 1 && val != ''){ let ss = SpreadsheetApp.getActiveSpreadsheet(); let sheet = ss.getSheetByName(source.getName()); let targetSheet = ss.getSheetByName(val); let data = sheet.getRange(row,1,1,sheet.getLastColumn()).getValues(); targetSheet.insertRowBefore(2); targetSheet.getRange(2,1,1,data[0].length).setValues(data); sheet.deleteRow(row); } }
@SheetsNinja
@SheetsNinja 7 месяцев назад
Just added a comment with the updated code to add new rows to the top instead of the bottom.
@user-cd9ok2rv5y
@user-cd9ok2rv5y 7 месяцев назад
thank you!!!@@SheetsNinja
@user-is6vv2yf5t
@user-is6vv2yf5t Год назад
How do you copy a row to a different tab instead of deleting the information from the original sheet/tab? I.e.: Master sheet has names/demographics, Column has dropdown categories of sports, Sport is selected and copied to Tab with sport of same name WITHOUT deleting from master list. These tabs will be protected to certain viewers. Is it as simple as "copyRow" instead of "deleteRow"?
@SheetsNinja
@SheetsNinja Год назад
Just delete the row of the script with .deleteRow() and it will copy instead of move.
@justinchester753
@justinchester753 17 дней назад
Is there a way I can add in two scripts that is looking at criteria in two different columns? Meaning I move row 1 to its selected tab first. Then based off of the criteria I select in Column 2 it'll move to its corresponding tab as well.
@SheetsNinja
@SheetsNinja 17 дней назад
You can nest if statements if you want multiple criteria... something like this: if (val == 'tab name') { let column2Text = sheet.getRange(row,2).getValue(); let data = sheet.getRange(row,1,1,10).getValues(); let targetTab = ss.getSheetByName(val); targetTab.appendRow(data[0]); if (column2Text == 'tab 2 name') { // copy row to other tab as well let sheet2 = ss.getSheetByName("tab2"); sheet2.appendRow(data[0]); } } If you notice, the ending bracket for the first if statement is OUTSIDE of the second if statement. This is how you nest them, which allows you to do something if the first condition is true, but have a nested action that only applies if something else if the case.
@jessespiegel6915
@jessespiegel6915 2 месяца назад
Thanks for this! It's working except that it is not moving the dropdown selection. I click the dropdown in column A, select the appropriate category (that corresponds exactly to a tab), it moves the row to that tab but the drop down selection is returned to no selection. All the other info is intact. I saw a comment about the top row being frozen causing problems so I unfroze my top row but it is still not moving the drop down selection. Any advice would be welcomed and appreciated!
@SheetsNinja
@SheetsNinja 2 месяца назад
I don't know if you have a line of code in your script that's something like: data[0][0] = '' But if you do, you will want to delete that line because it would be clearing the value out of column A in the data getting moved. Otherwise, it should be working if your script looks like what we built in the video.
@jessespiegel6915
@jessespiegel6915 2 месяца назад
@@SheetsNinja I had something like that, deleted it and now it works. Amazing how quickly you responded! Truly impressed but the content and support you are providing. As for that piece of code, I copied and pasted the entire code you linked to in the description. Just double checked and confirmed that line is in your code as well. Guessing you know that but just in case thought I would share that info. Thanks again!
@abbyy00141
@abbyy00141 10 дней назад
Hi there! You videos are helpful! BUT Do you have a video about How to move a row to bottom of sheet when "Status" is changed to a value???
@SheetsNinja
@SheetsNinja 10 дней назад
I have a similar video here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-HJlpzGvzw30.html But instead of the finding section header, you could just change the target to: sheet.getRange(sheet.getLastRow()+1,1,1,data[0].length).setValues(data);
@abbyy00141
@abbyy00141 7 дней назад
@@SheetsNinja Thank you!
@yeasinhossain8234
@yeasinhossain8234 8 месяцев назад
Many thanks for providing such a simple script! BTW, I'm having trouble adding checkboxes to a row. After moving it, it becomes a plain text line True/False😥😥
@SheetsNinja
@SheetsNinja 8 месяцев назад
So usually I will just add a line to the script after the new data gets added, something like this: targetSheet.getRange(targetSheet.getLastRow(),checkbox_column).insertCheckboxes();
@user-le4ne5ve6x
@user-le4ne5ve6x 11 месяцев назад
can you provide a code for moving copying/moving row to a different spreadsheet ? now just a sheet within the spreadsheet ?
@SheetsNinja
@SheetsNinja 11 месяцев назад
I just recorded a new video showing how to move to a different spreadsheet: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-9xDQhwtkBWM.html
@FazilUmmer_
@FazilUmmer_ Год назад
hey ninja first of all thank for this script,i got an issue when i select lead the whole row went to sales.i have importrange data.
@SheetsNinja
@SheetsNinja Год назад
So if you have importrange data, this won't work the same as the importrange data is dynamic. So you could use the importrange for your initial stage, you just won't be able to delete the row when it copies the data to the new status tab.
@nathanuyami9524
@nathanuyami9524 Год назад
is there a way for me to add another row once I transfer a row into a new one?
@SheetsNinja
@SheetsNinja Год назад
I'm not quite sure what you mean? Are you talking about using the script to move a row or are you talking about entering data?
@JulianaAristizabal-lq6rc
@JulianaAristizabal-lq6rc 2 месяца назад
Hi!! Thank you so much, I have a question, I was able to copy and paste the rows into another sheet, but the hyperlinks I had didn't get copied, only the names did. Do you know how I can make sure the hyperlink gets copied and pasted as well?
@SheetsNinja
@SheetsNinja 2 месяца назад
replace the .getValues() and .appendRow() lines with these: let data = sheet.getRange(row, 1, 1, sheet.getLastColumn()).getRichTextValues(); targetSheet.getRange(targetSheet.getLastRow() + 1, 1, 1, data[0].length).setRichTextValues(data); targetSheet.getRange(targetSheet.getLastRow(), 1).clearContent();
@JulianaAristizabal-lq6rc
@JulianaAristizabal-lq6rc 2 месяца назад
@@SheetsNinja It isn't working... not sure if I am copying wrong! function onEdit(e){ let range = e.range; let col = range.getColumn(); let row = range.getRow(); let val = range.getValue(); let source = e.source.getActiveSheet(); if (col == 1 && val != ''){ let ss = SpreadsheetApp.getActiveSpreadsheet(); let sheet = ss.getSheetByName(source.getName()); let targetSheet = ss.getSheetByName(val); let data = sheet.getRange(row, 1, 1, sheet.getLastColumn()).getRichTextValues(); targetSheet.getRange(targetSheet.getLastRow() + 1, 1, 1, data[0].length).setRichTextValues(data); targetSheet.getRange(targetSheet.getLastRow(), 1).clearContent(); sheet.deleteRow(row); } }
@SheetsNinja
@SheetsNinja 2 месяца назад
That should do it if you're doing direct links. If you're doing a hyperlink formula (e.g. =hyperlink("www.google.com","Google"), you'll want to follow the modifications from this video: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-E1w7VnFWsZA.html
@YOLOPRODUCTI0NS
@YOLOPRODUCTI0NS 2 месяца назад
@@SheetsNinja the appscript in the youtube you shared is still not copying over the URL in the hyperlinked text from one sheet to the other
@SheetsNinja
@SheetsNinja 2 месяца назад
@@YOLOPRODUCTI0NS So I proposed two different solutions depending on what you're doing. If you're doing formulas (e.g. =hyperlink() , you need to follow the instructions in this video to merge the data and the formulas: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-E1w7VnFWsZA.html Otherwise if you're using the link shortcut direclty in the cell, then you need to use the .getRichTextValues() as suggested in the comment above.
@anchit-italiagroup5715
@anchit-italiagroup5715 Год назад
Hello !! Thanks for the Script. Just one challenge that i am facing is when the row shifts to the target sheet it is deleting the subsequent row. Please guide. Thanks
@SheetsNinja
@SheetsNinja Год назад
So if you're using the script as-is, it will work fine, but if you're incorporate some other things in the script it may be shifting things before it deletes the row.
@anchit-italiagroup5715
@anchit-italiagroup5715 Год назад
@@SheetsNinja This is the Script that i am using there is no change that i have done other than the Column number /* @OnlyCurrentDoc */ function onEdit(e){ let range = e. range; let col = range.getColumn(); let row = range.getRow(); let val = range.getValue(); let source = e.source.getActiveSheet(); if (col == 19 && val != ''){ let ss = SpreadsheetApp.getActiveSpreadsheet(); let sheet = ss.getSheetByName(source.getName()); let targetSheet = ss.getSheetByName(val); let data = sheet.getRange(row,1,1, sheet .getLastColumn()).getValues(); targetSheet.appendRow(data[0]); sheet.deleteRow(row); } }
@CierraGonzalez-nh5pv
@CierraGonzalez-nh5pv 2 месяца назад
Thank you so much for this! I've been searching everywhere for this! How do you move it back and forth between the sheets, once its been moved? The script works perfectly to move it from main sheet to the other sheets but I can't move it back or between the sheets I tried one of the other scripts from another comment but it doesn't seem to be working and I'm not sure where to add it in to the original script (i just put it at the bottom) My Original Tab is "PENDING ORDERS" and the drop down is "NOT STARTED" " if (val == "NOT STARTED") { let targetSheet = ss.getSheetByName('PENDING ORDERS"); targetSheet.appendRow(data[0]); "
@SheetsNinja
@SheetsNinja 2 месяца назад
So the easiest way is to have the drop-down match the tab name and then you don't have to add anything extra. Otherwise you will want to add this part in before the closing bracket.
@AndrewMeyers-te9cu
@AndrewMeyers-te9cu 2 месяца назад
Would You be able to help me with a similar project? I am trying to use your script and getting an error with the range. I added tow additional sheets to the workbook but they will not cycle, please help if you can!
@SheetsNinja
@SheetsNinja 2 месяца назад
So if you have the same columns on the different sheets, just make sure the drop-down values are the same as the tab names, and then everything should work the same.
@virajsharma4465
@virajsharma4465 2 месяца назад
Nice Video, the only issue i am facing is the status is not getting send to the new sheet. all data is being moved except the status. please suggest what can be the possible issue.
@SheetsNinja
@SheetsNinja 2 месяца назад
Just remove this line from the code: data[0][0] = ''
@virajsharma4465
@virajsharma4465 Месяц назад
Hi buddy, the sheet was working fine but now I am facing issue that the data is getting deleted after shifting to done sheet from my id. But when my team is doing done, it is being shifted to the done sheet but is not being deleted from master sheet. Please help!!!
@tianolamas7832
@tianolamas7832 13 дней назад
Hi, I use this code but it doesn’t keep the format between the tabs. Is there a code line that I should add besides “Rich Text Value” ex, it copies hyperlink but it has black letters instead of the blue letters underlined
@SheetsNinja
@SheetsNinja 13 дней назад
You can copy formats as well, but the method is a lot more complicated. It's something like: sheet.getRange(row,col,numRows,numCols).copyFormatToRange(targetSheetId, startRow,endRow,startCol,endRow)
@user-bp5mp8wk9o
@user-bp5mp8wk9o 2 месяца назад
Very helpful Ninja. Thanks. I just don't know why when I click on the drop-down, the row moves perfectly but when another user does it, The row info is copied but it does not disappear from the main sheet. Any suggestions?
@SheetsNinja
@SheetsNinja 2 месяца назад
It sounds like the other user may not have restricted permissions on the main sheet. If you do not want to modify the permissions, you may want to do an installed onEdit trigger instead. (Change the function name from "function onEdit(e) {" to something like "function checkMySheet(e) {" And then on the left hand side, you will see a clock icon, click on that, then the plus sign on the lower right on the new screen, then on the popup, you'll want to select the new function name on the first drop-down, then for the the next few fields, you'll want this: Head (for deployment) Spreadsheet On edit Then click save and that new trigger will run the same script for everyone but with your permissions so it will work even if you are restricting access for certain users.
@user-bp5mp8wk9o
@user-bp5mp8wk9o 2 месяца назад
@@SheetsNinja is kind of strange 'cause the other users are "editors" too.
@user-bp5mp8wk9o
@user-bp5mp8wk9o 2 месяца назад
@@SheetsNinja I started from scratch and did what you suggested (installed onEdit trigger) It works like a charm.. Ninja is the best! thanks again.
@xlostlovex
@xlostlovex 5 месяцев назад
How do I in another scenario, after ticking a check box (Example row 20) then it will proceed to move up to row 2? The scenario is that I will have lets say 30 row of random data, and a check box on each row, after I check, it will rearrange to the top. So if I check row 20 now, it goes to row 2, I check row 15, it goes to row 3, I check row 21, it goes to row 4 and so forth? Cause I want to keep track in order the task I did after checking everything.
@SheetsNinja
@SheetsNinja 5 месяцев назад
Here is the apps script method: developers.google.com/apps-script/reference/spreadsheet/sheet#moverowsrowspec,-destinationindex So where they do .getRange("A2:A3"), you could do .getRange(row,column) and then set the new index to 2.
@xlostlovex
@xlostlovex 5 месяцев назад
@@SheetsNinja Ty so much!
@tinay5082
@tinay5082 Месяц назад
Hi, any help pls! I tried using the getRichTextValues as I have data with hyperlink but the number values/data within the row (for example, dates and simple 1,2,3, numbers) disappear. What should I do?
@SheetsNinja
@SheetsNinja Месяц назад
So you can use the same logic as this video: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-E1w7VnFWsZA.html Just swap out where it uses .getFormulas() and .setFormulas() for .getRichTextValues() and .setRichTextValues()
@OSCARPION09
@OSCARPION09 2 месяца назад
Thank you for your help. one more question. my dropdown is in column "C". So i changed the script to: if (col == 3 && val != ''){ ( My sheet columns are: "A"= Room#, "B"= Date, and "C"= Satus ) When applying the script everything is moved except values in column "A". The column is empty. Is there a way to fix this issue?
@SheetsNinja
@SheetsNinja 2 месяца назад
You'll just need to delete one row in the code, which looks like this: data[0][0] = '';
@OSCARPION09
@OSCARPION09 2 месяца назад
@@SheetsNinja Thank you, it works perfectly.
@rizalfanani9512
@rizalfanani9512 Год назад
hey great videos, i tried it and it work well but not as i wanted. the data i copied is many (more than 10000 rows) and when i pasted it, it only move the first data i pasted. the values is on coloumn 2 too for my data, i changed the code to coloumn 2 but i have to pasted again the data to coloumn 2 and like i said it just move the data of the first row i copied. how can i make it to move all the data i pasted on coloumn 1 (A) based on the value on coloumn 2 (B) to another tab that have the same name as the value? and on excell i use a button to start the script for looking the value on coloumn 2 (B) then it move the data to the tab/sheet that have the same name as value, how can i do that on google spreadsheet?
@SheetsNinja
@SheetsNinja Год назад
So if you're needing to handle multiple rows, you can't use an onEdit trigger as it can't properly handle input from multiple rows. So you have to write the script to scan multiple rows and determine the destination. You could use a button to trigger when this happens, or you could try using an OnChange trigger. One thing to keep in mind is that you will probably need to use a column to mark what rows have been processed so you don't keep copying the same rows of data again every time the script runs.
@rizalfanani9512
@rizalfanani9512 Год назад
@@SheetsNinja ah yes it only have to scan the coloumn 2 (B) for a values that is same as another sheet and after i pasted the data, it can move all the data row to a specif sheet that have the same name as the value. it can be triggered by a button or move the data instantly after i pasted it, but i dont know coding and so far searched the internet i have no success to find someone that making that code. can you assist me by making a video about it or guide me of how the code should be? i can show you the google spread that i use with the data too if you want
@SheetsNinja
@SheetsNinja Год назад
I just recorded a new video to explain how to move multiple rows of data at once: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-NwULKMo7ygs.html
@rizalfanani9512
@rizalfanani9512 Год назад
@@SheetsNinja wow thanks dude you really are a life saver! I will try the code later. Thank you very much 🙏
@brianhickey7968
@brianhickey7968 5 месяцев назад
Hi Ninja! I got the sheet running and everything was going wonderfully but now random drop downs won’t transfer sheets. 95% of the drop downs work as intended. It seems completely random and it’s on multiple sheets
@SheetsNinja
@SheetsNinja 5 месяцев назад
So often on a case like this, there might be a slight mismatch between the drop-down and the tab name. Most common is a space (which obviously is invisible unless you edit the value or the tab name).
@brianhickey7968
@brianhickey7968 5 месяцев назад
I will try and see if that is what happened!!!
@brianhickey7968
@brianhickey7968 5 месяцев назад
I did try and match everything up and it does match. What it turns out is the problem is it IS MOVING the data but it isn’t deleting the row once it’s done. Again it does appear random, at least as far as I can tell.
@SheetsNinja
@SheetsNinja 4 месяца назад
@@brianhickey7968 One thing that can happen is if you have the header row frozen and the script is trying to delete the only row in the tab below the frozen header, it will error out and not delete that row. In that case, I have to add an if/else statement to the script, something like this: if (row == 2) { sheet.getRange(2,1,1,sheet.getLastColumn()).clearContent() } else { sheet.deleteRow(row) }
@juliuskonge4947
@juliuskonge4947 11 месяцев назад
How do make it so it copies the function inside the cell and not only the value?
@SheetsNinja
@SheetsNinja 11 месяцев назад
You can copy formulas using .getFormulas and .setFormulas instead of .getValues() and .setValues()
@juliuskonge4947
@juliuskonge4947 11 месяцев назад
@@SheetsNinja Hi again, Thanks for the answer. Now i can make it move the formulas, but only the formulas. The rows i have is both Values and Formulas. I can see other people in the comments are looking for the same thing. Is it something u can help us with ? :) Thanks alot again. Very nice video
@SheetsNinja
@SheetsNinja 11 месяцев назад
You're in luck, I had time to record another quick video on this topic, you can see it here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-i2VgEclS4ps.html
@forcenick
@forcenick Год назад
Is it possible to do this between 2 different spreadsheets?
@SheetsNinja
@SheetsNinja Год назад
Yes, instead of just referencing a different tab for the target, you would use something like: let targetSS = SpreadsheetApp.openById('SS_ID'); let targetSheet = targetSS.getSheetByName('TARGET_TAB');
@forcenick
@forcenick Год назад
@@SheetsNinja incredible, I just started to learn javascript so I can learn google app script easier.
@Sepjuu
@Sepjuu Год назад
Hi @Sheets Ninja, this should work but for some reason mine didnt. I have same script from the vid
@vediuniforms9886
@vediuniforms9886 Год назад
hey sheets ninja good work.., can you please add a code in this for move drop down tooo.... thanks waitng for your rply
@SheetsNinja
@SheetsNinja Год назад
Hey, so all you have to add is two lines, one to get the data validations and the other to set them. E.g. something like this: let validations = sheet.getRange(row,1,1,sheet.getLastCplumn()).getDataValidations(); targetSheet.getRange(newRow,1,1,validations.length).setDataValidations(validations);
@vediuniforms9886
@vediuniforms9886 Год назад
@@SheetsNinja thank you for your reply i will testifies it and rply you soon thanks for your help
@adamnipperess910
@adamnipperess910 28 дней назад
Yeh, couldn't get this to work. Tried everything but the line of data just wouldn't transfer onto the other sheet. Thanks for the tutorial though. Much appreciated.
@SheetsNinja
@SheetsNinja 28 дней назад
Typically the issues with the simplest version here is that the tab names don't match exactly (sometimes tab names have a space at the beginning or end, if you try renaming it see if there is a blank space), otherwise if you have dropdowns with different values on the other tab, it may be returning an error if you're trying to move data that doesn't match the drop-down options. If you are using appendRow(data[0]) you need to make sure you use the [0], and finally, if you haven't authorized the script, it won't work either.
@adamnipperess910
@adamnipperess910 27 дней назад
@@SheetsNinja Thanks for your reply, greatly appreciated! I have double checked the naming of the sheets and trigger word but still cant seem to get it to work. All I was trying to do is create a simple 1 column drop down with the word "Archive" in it to move that line of information into an Archive tab sheet. The only difference I can see between your coding and mine is that where the drop down lives is on column 9 instead of 1. So the source sheet is Form responses 1 and the Archive sheet is simply Archive. I select Archive from a dropdown on the line of information I want to send to the Archive sheet and it deletes it from Form responses 1 sheet and places it in the Archive sheet. I have followed your coding with great appreciation and given authorisation, double and triple checked the spelling and made sure there were no spaces at the beginning, but I still cant seem to get it to work. /* @OnlyCurrentDoc */ function onEdit(e){ let range = e.range; let col = range.getColumn(); let row = range.getRow(); let val = range.getValue(); let source = e.source.getActivesheet(); if (col == 1 && val !=''){ let ss = SpreadsheetApp.getActiveSpreadsheet(); let sheet = ss.getSheetbyName(source.getName()); let targetSheet = ss.getSheetByName(val); let data = sheet.getRange(row,1,9,sheet.getLastColumn()).getValues(); targetSheet.appendRow(data[0]); sheet.deleteRow(row); } } Am I missing something?
@dreamprep2665
@dreamprep2665 Месяц назад
I am facing a small issue that when the data is transferred the date format is changed from 6-May to 6/05/2024 and i have to change that again to 06 may everytime and for every column.. can you please provide me a solution for this??
@SheetsNinja
@SheetsNinja Месяц назад
So what you'll want to add into the script is a line to add the number format to change the format into the desired date format. Something like this (assuming column with the data is 6) targetSheet.getRange(2,6,targetSheet.getLastRow()-1,1).setNumberFormat("d-MMM");
@dreamprep2665
@dreamprep2665 Месяц назад
@@SheetsNinja thanks a lot brother. You are truly an genius and way too helpful for me...
@dreamprep2665
@dreamprep2665 Месяц назад
@@SheetsNinja Keep on growing brother 😇🫡🫡
@ReaElaenaGalang
@ReaElaenaGalang 3 месяца назад
Tried it, it works but the hyperlinks are not copied :( can you help?
@SheetsNinja
@SheetsNinja 3 месяца назад
I have another video showing how to copy hyperlinks: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-E1w7VnFWsZA.html The short version is using .getRichTextValues() and .setRichTextValues() instead of .getValues() and .setValues()
@ReaElaenaGalang
@ReaElaenaGalang 3 месяца назад
@@SheetsNinja Thank you so much!
@ReaElaenaGalang
@ReaElaenaGalang 2 месяца назад
@@SheetsNinja hi sorry but im confused where should i put this short version? there's only .getValues() but there's no .setValues() in the script, even on the video you linked and the updated script.
@SheetsNinja
@SheetsNinja 2 месяца назад
@@ReaElaenaGalang so the script I did above uses targetSheet.appendRow(data[0]) so what you would do instead is this: targetSheet.getRange(targetSheet.getLastRow()+1,1,1,data[0].length).setRichTextValues(data);
@soufianeez2770
@soufianeez2770 5 месяцев назад
great i have the code, now how to applay the code???
@SheetsNinja
@SheetsNinja 5 месяцев назад
You can download the template from the link, if you search my channel for apps script, I have videos covering many things from authorizing the script to various applications.
@musaddik006
@musaddik006 Месяц назад
Not working with my sheet can u help me out
@SheetsNinja
@SheetsNinja Месяц назад
There are a couple of common errors; 1. Are you referring to the correct column in the script (where it says "if (col == 1..."). If you are using column E for the status selection instead of A, you would want that to be col == 5 instead. 2. Do the tab names match the drop-down selections? If not you will need to map that in the script, so make sure you check out the next video (linked in the description above) 3. Did you authorize the script? If you have not authorized the script it will not run.
@musaddik006
@musaddik006 Месяц назад
@@SheetsNinja I named the column as 7 but I don't want drop-down I want it to be entered manually.... Wouldn't that work if I enter manually instead of drop-down... I've authorised and ran too but didn't work
@SheetsNinja
@SheetsNinja Месяц назад
The problem with entering manually is if what you enter doesn't match the tab name or your reference then it will have an error. An error here can be as simple as an extra space in what you type in.
@sabirkoibrahim257
@sabirkoibrahim257 28 дней назад
It difficult
@SheetsNinja
@SheetsNinja 28 дней назад
Apps Script can be confusing when you first get started. You can try downloading the template and checking out the completed code there and hopefully that helps you to start getting a better grasp on it.
@YeniferMezquita
@YeniferMezquita 19 дней назад
Can't get it to work - Not sure why. This is my script: /* @OnlycurrentDoc */ function onEdit(e){ let range = e.range; let col = range.getColumn(); let row = range.getRow(); let val = range.getValue(); let source = e.source.getActiveSheet(); if (col == 1 && val != ''){ let ss = Spreadsheet.getActiveSheet(); let sheet = ss.getSheetByName(source.getName()); let targetSheet = ss.getSheetByName(val); let data = sheet.getRange(row,1,1,sheet.getLastColumn()).getValue(); targetSheet.appendRow(data[0]); sheet.deleteRow(row); } }
@SheetsNinja
@SheetsNinja 19 дней назад
A couple of reasons why this could be... Is your drop-down in column A? And do the drop-down options match the tab names exactly? And finally, did you authorize the script?
@jonathankobz8764
@jonathankobz8764 Год назад
I'm getting this error, I just copied and paste the script you had "Execution log 9:21:30 PM Notice Execution started 9:21:30 PM Error TypeError: Cannot read properties of undefined (reading 'range') onEdit @ Code.gs:6
@SheetsNinja
@SheetsNinja Год назад
So you always get that error the first time you try to run the onEdit trigger directly, but as long as the script is working when you use the dropdowns, it will be fine.
@farihahossain7474
@farihahossain7474 Год назад
I tried this, my stats Col= 7 as my sheet Col is G that's why I wrote if (col==7 && val!=' ') but doesn't move my data can you suggest me. or Send me your email address so that I can send you SS or Recording
@SheetsNinja
@SheetsNinja Год назад
Did you try using the script as is first before you modified it? Just to make sure you got everything working first.
@brianhickey7968
@brianhickey7968 5 месяцев назад
@@SheetsNinjaI am also having this problem. I tried to move my data to column one to see if that would work and it doesn’t. So I went back through the code looking for errors. The only thing I could see is line 14 and 16. The parenthesis inside the close parenthesis are blue not black. I’m not sure why or if that is a problem.
@brianhickey7968
@brianhickey7968 5 месяцев назад
@@SheetsNinjaI checked on edit and I get two errors. Value is not defined Code:12:19 and Cannot read properties of undefined reading range Code:6:17
Далее
Automatically Sort New Rows in Google Sheets
8:08
Просмотров 10 тыс.
Highlights: Spanje - Gjeorgji
06:17
Просмотров 552 тыс.
Move All Checked Rows
12:11
Просмотров 5 тыс.
Google Sheets: Move Entire Row with Dropdown
3:02
Просмотров 42 тыс.
Google Sheets: Move Entire Row with Checkbox
2:46
Просмотров 62 тыс.
Move Rows With Different Tab Names - Dropdown
12:06
Просмотров 5 тыс.