Apologies if this thread have already been listed or if I am doing something wrong for what ever reason, I don’t know forums that well.
I have a piece of code that I am struggling with. I started using google sheets recently and as oppose to Microsoft excel sheets which uses VBA, google sheets uses Java coding which I am not familiar with.
All I want to do, is to move a row from one sheet to another once it has been marked as done in the 4th cell. So either move it or copy it to second sheet and delete it from original sheet.
Here is my online document I have – https://docs.google.com/spreadsheets/d/1kzzSH5WaJFdU4I76CAjDKpBSfGK3iglZ3mGid00oldQ/edit?usp=sharing
Here is the code I used in Excel;
Sub button()
For Each myCell In Selection.Columns(4).Cells
If myCell.Value = "Done" Then
myCell.EntireRow.Copy Worksheets("Done").Range("A" & Rows.Count).End(3)(2)
myCell.EntireRow.Delete
End If
Next
End Sub
Thank you in advance.
I tried finding a VBA to Java language converter, but did not succeed. I tried using the google sheet language converter, but it told me that I need to pay or subscribe or something, (am living in a third world Country, I prefer food over luxury).
I tried googling code, but to no avail and finally I tried writing my own code, but did not succeed.
I struggle to find time to learn the Java coding as I work 2 jobs a day to make a living.
Again, I am very sorry for asking help here.
Here is the code that I wrote and tried that did not work.
function Button(d) {
var activeSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var DoneSheet = activeSpreadsheet.getSheetByName('Done');
var activeSheet = SpreadsheetApp.getActiveSheet();
var numColumns = activeSheet.getLastColumn();
var cell = d.range;
var value = activeSheet.getLastColumn.value;
var lock = LockService.getScriptLock();
if (activeSheet.getSheetName() == 'Dev Jobs' && activeSheet.getLastColumn.value == 'Done') {
lock.tryLock(10000);
if (!lock.hasLock()) {
activeSpreadsheet.toast('The Spreadsheet is busy currently, please try again in a bit.');
} else {
var row = activeSheet.getRange(cell.getRow(), 1, 1, numColumns).getValues();
DoneSheet.appendRow(row[0]);
activeSheet.deleteRow(cell.getRow());
}
}
}
I tried this;
if (activeSheet.getSheetName() == 'Dev Jobs' && activeSheet.getLastColumn.value == 'Done') {
lock.tryLock(10000);
if (!lock.hasLock()) {
activeSpreadsheet.toast('The Spreadsheet is busy currently, please try again in a bit.');
} else {
var row = activeSheet.getRange(cell.getRow(), 1, 1, numColumns).getValues();
DoneSheet.appendRow(row[0]);
activeSheet.deleteRow(cell.getRow());
}
}
}
2
Answers
Here is an example of moving specific rows to another sheet. This process will only work with values as formula references may break down.
Reference