Reputation: 11
I am trying to copy data from COPY SHEET to PASTE SHEET and once complete I want to data in the copy sheet to clear.
COPY SHEET INFORMATION
Information is in Column B
Priority A - High
First Name New Test
Last Name test
Company JLC
Phone Number 3065551212
Email [email protected]
Notes Likes Coffee
Call Back Date 3/7/2022
Date Entered 3/26/2023
Address 679 Rink Ave, Regina SK S4X2P3
PASTE SHEET Information needs to be put into columns A-L
First Name Last Name Company Phone Number Email Notes Call Back Date Date Entered Address
function copyInfo() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var copySheet = ss.getSheetByName("Contact Form");
var pasteSheet = ss.getSheetByName("CRM");
// get source range
var source = copySheet.getRange(B1:B10);
// get destination range
var destination = pasteSheet.getRange(A2:L2);
// copy values to destination range
source.copyTo(destination);
// clear source values
source.clearContent();
}
Upvotes: 0
Views: 29
Reputation: 201358
B1:B10
and A2:L2
of var source = copySheet.getRange(B1:B10);
and var destination = pasteSheet.getRange(A2:L2);
are required to be set as the string.When these points are reflected in your script, it becomes as follows.
function copyInfo() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var copySheet = ss.getSheetByName("Contact Form");
var pasteSheet = ss.getSheetByName("CRM");
// get source range
var source = copySheet.getRange("B1:B10");
// get destination range
var destination = pasteSheet.getRange("A2:L2");
// copy values to destination range
source.copyTo(destination, SpreadsheetApp.CopyPasteType.PASTE_NORMAL, true);
// clear source values
source.clearContent();
}
When this script is run, the values of "B1:B10" of "Contact Form" is copied to "A2:L2" of "CRM". And, "B1:B10" of "Contact Form" is cleared.
For example, if you want to append the values to the destination sheet, please modify var destination = pasteSheet.getRange("A2:L2");
as follows.
var lastRow = pasteSheet.getLastRow() + 1;
var destination = pasteSheet.getRange(lastRow == 1 ? 2 : lastRow, 1);
Upvotes: 0