Reputation: 1
I'm trying to do a simple script to transfer the entire line to "Sheet2" every time that the word "Correct" is typed on the 5th Column of the Sheet1.
What is wrong with the code below? Its doesnt works. And, sometimes, the following error message appears:
ReferenceError: "value" is undefined. (line 2, file "Resize")
function onEdit(e){
if(e.value != "Correct" || e.range.columnStart != 5) return;
dest = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2");
e.range.offset(0,-5,1,e.source.getActiveSheet().getLastColumn()).moveTo(dest.getRange(dest.getLastRow()+1,1,1,e.source.getActiveSheet().getLastColumn())); }
If this could help, I have the same function on VBA:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 5 Then Exit Sub
If Target.Value <> "Correct" Then Exit Sub
Dim LR As Long
With Sheets("Sheets2")
LR = .Cells(Rows.Count, 1).End(xlUp).Row
.Cells(LR + 1, 1).Resize(, 4).Value = Cells(Target.Row, 1).Resize(, 4).Value
End With
Rows(Target.Row).Delete
End Sub
Upvotes: 0
Views: 41
Reputation: 26806
If e.range.columnStart
is 5, then e.range.offset(0,-5)
would be column 0, which is obviously not possible.
Upvotes: 2