Adding a time stamp to copied column
I am using this script to copy a column from one report and record it in a historical log:
function copyDailyreport() {
var sheetFrom = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("MSM");
var sheetTo = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("MSM Daily Totals");
var valuesToCopy = sheetFrom.getRange(4, 11, sheetFrom.getLastRow(), 1).getValues();
sheetTo.getRange(1,sheetTo.getLastColumn()+1,valuesToCopy.length,1).setValues(valuesToCopy);
}
The code is working great and does what I want, but I would like to add a time stamp to the column either above or below the copied information.
I've tried a couple different things and have not been successful. I imagine it's something simple and I've over complicated it.
Thanks in advance for your help!
add a comment |
I am using this script to copy a column from one report and record it in a historical log:
function copyDailyreport() {
var sheetFrom = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("MSM");
var sheetTo = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("MSM Daily Totals");
var valuesToCopy = sheetFrom.getRange(4, 11, sheetFrom.getLastRow(), 1).getValues();
sheetTo.getRange(1,sheetTo.getLastColumn()+1,valuesToCopy.length,1).setValues(valuesToCopy);
}
The code is working great and does what I want, but I would like to add a time stamp to the column either above or below the copied information.
I've tried a couple different things and have not been successful. I imagine it's something simple and I've over complicated it.
Thanks in advance for your help!
above/below the row or before/after the column?
– shabnam bharmal
Nov 12 '18 at 4:58
above or below would be best. Right now the column copies into the new sheet next to the previous column.
– Amber Weiand
Nov 14 '18 at 0:56
add a comment |
I am using this script to copy a column from one report and record it in a historical log:
function copyDailyreport() {
var sheetFrom = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("MSM");
var sheetTo = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("MSM Daily Totals");
var valuesToCopy = sheetFrom.getRange(4, 11, sheetFrom.getLastRow(), 1).getValues();
sheetTo.getRange(1,sheetTo.getLastColumn()+1,valuesToCopy.length,1).setValues(valuesToCopy);
}
The code is working great and does what I want, but I would like to add a time stamp to the column either above or below the copied information.
I've tried a couple different things and have not been successful. I imagine it's something simple and I've over complicated it.
Thanks in advance for your help!
I am using this script to copy a column from one report and record it in a historical log:
function copyDailyreport() {
var sheetFrom = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("MSM");
var sheetTo = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("MSM Daily Totals");
var valuesToCopy = sheetFrom.getRange(4, 11, sheetFrom.getLastRow(), 1).getValues();
sheetTo.getRange(1,sheetTo.getLastColumn()+1,valuesToCopy.length,1).setValues(valuesToCopy);
}
The code is working great and does what I want, but I would like to add a time stamp to the column either above or below the copied information.
I've tried a couple different things and have not been successful. I imagine it's something simple and I've over complicated it.
Thanks in advance for your help!
asked Nov 12 '18 at 4:32
Amber Weiand
61
61
above/below the row or before/after the column?
– shabnam bharmal
Nov 12 '18 at 4:58
above or below would be best. Right now the column copies into the new sheet next to the previous column.
– Amber Weiand
Nov 14 '18 at 0:56
add a comment |
above/below the row or before/after the column?
– shabnam bharmal
Nov 12 '18 at 4:58
above or below would be best. Right now the column copies into the new sheet next to the previous column.
– Amber Weiand
Nov 14 '18 at 0:56
above/below the row or before/after the column?
– shabnam bharmal
Nov 12 '18 at 4:58
above/below the row or before/after the column?
– shabnam bharmal
Nov 12 '18 at 4:58
above or below would be best. Right now the column copies into the new sheet next to the previous column.
– Amber Weiand
Nov 14 '18 at 0:56
above or below would be best. Right now the column copies into the new sheet next to the previous column.
– Amber Weiand
Nov 14 '18 at 0:56
add a comment |
2 Answers
2
active
oldest
votes
You can use the appendRow method to add a new row after the copy operation is complete.
sheetTo.appendRow([new Date()]);
The code adds the date, but to a new row below, but not under the new data entered in the column.
– Amber Weiand
Nov 14 '18 at 2:00
add a comment |
This will work with unshift method which will append the timestamp at the start of the column
function copyDailyreport() {
var timeStamp=Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "MM/dd/yyyy");
var now= new Date(),
h= now.getHours(),
m= now.getMinutes(),
s= now.getSeconds(),
timeStamp=timeStamp+" "+h+":"+m+":"+s ;
var sheetFrom = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("MSM");
var sheetTo = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("MSM Daily Totals");
var valuesToCopy = sheetFrom.getRange(4, 11, sheetFrom.getLastRow(), 1).getValues();
valuesToCopy.unshift([timeStamp]);
sheetTo.getRange(1,sheetTo.getLastColumn()+1,valuesToCopy.length,1).setValues(valuesToCopy);
}
Hope this could help!.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255998%2fadding-a-time-stamp-to-copied-column%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use the appendRow method to add a new row after the copy operation is complete.
sheetTo.appendRow([new Date()]);
The code adds the date, but to a new row below, but not under the new data entered in the column.
– Amber Weiand
Nov 14 '18 at 2:00
add a comment |
You can use the appendRow method to add a new row after the copy operation is complete.
sheetTo.appendRow([new Date()]);
The code adds the date, but to a new row below, but not under the new data entered in the column.
– Amber Weiand
Nov 14 '18 at 2:00
add a comment |
You can use the appendRow method to add a new row after the copy operation is complete.
sheetTo.appendRow([new Date()]);
You can use the appendRow method to add a new row after the copy operation is complete.
sheetTo.appendRow([new Date()]);
answered Nov 12 '18 at 7:46
Amit Agarwal
5,21611326
5,21611326
The code adds the date, but to a new row below, but not under the new data entered in the column.
– Amber Weiand
Nov 14 '18 at 2:00
add a comment |
The code adds the date, but to a new row below, but not under the new data entered in the column.
– Amber Weiand
Nov 14 '18 at 2:00
The code adds the date, but to a new row below, but not under the new data entered in the column.
– Amber Weiand
Nov 14 '18 at 2:00
The code adds the date, but to a new row below, but not under the new data entered in the column.
– Amber Weiand
Nov 14 '18 at 2:00
add a comment |
This will work with unshift method which will append the timestamp at the start of the column
function copyDailyreport() {
var timeStamp=Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "MM/dd/yyyy");
var now= new Date(),
h= now.getHours(),
m= now.getMinutes(),
s= now.getSeconds(),
timeStamp=timeStamp+" "+h+":"+m+":"+s ;
var sheetFrom = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("MSM");
var sheetTo = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("MSM Daily Totals");
var valuesToCopy = sheetFrom.getRange(4, 11, sheetFrom.getLastRow(), 1).getValues();
valuesToCopy.unshift([timeStamp]);
sheetTo.getRange(1,sheetTo.getLastColumn()+1,valuesToCopy.length,1).setValues(valuesToCopy);
}
Hope this could help!.
add a comment |
This will work with unshift method which will append the timestamp at the start of the column
function copyDailyreport() {
var timeStamp=Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "MM/dd/yyyy");
var now= new Date(),
h= now.getHours(),
m= now.getMinutes(),
s= now.getSeconds(),
timeStamp=timeStamp+" "+h+":"+m+":"+s ;
var sheetFrom = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("MSM");
var sheetTo = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("MSM Daily Totals");
var valuesToCopy = sheetFrom.getRange(4, 11, sheetFrom.getLastRow(), 1).getValues();
valuesToCopy.unshift([timeStamp]);
sheetTo.getRange(1,sheetTo.getLastColumn()+1,valuesToCopy.length,1).setValues(valuesToCopy);
}
Hope this could help!.
add a comment |
This will work with unshift method which will append the timestamp at the start of the column
function copyDailyreport() {
var timeStamp=Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "MM/dd/yyyy");
var now= new Date(),
h= now.getHours(),
m= now.getMinutes(),
s= now.getSeconds(),
timeStamp=timeStamp+" "+h+":"+m+":"+s ;
var sheetFrom = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("MSM");
var sheetTo = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("MSM Daily Totals");
var valuesToCopy = sheetFrom.getRange(4, 11, sheetFrom.getLastRow(), 1).getValues();
valuesToCopy.unshift([timeStamp]);
sheetTo.getRange(1,sheetTo.getLastColumn()+1,valuesToCopy.length,1).setValues(valuesToCopy);
}
Hope this could help!.
This will work with unshift method which will append the timestamp at the start of the column
function copyDailyreport() {
var timeStamp=Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "MM/dd/yyyy");
var now= new Date(),
h= now.getHours(),
m= now.getMinutes(),
s= now.getSeconds(),
timeStamp=timeStamp+" "+h+":"+m+":"+s ;
var sheetFrom = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("MSM");
var sheetTo = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("MSM Daily Totals");
var valuesToCopy = sheetFrom.getRange(4, 11, sheetFrom.getLastRow(), 1).getValues();
valuesToCopy.unshift([timeStamp]);
sheetTo.getRange(1,sheetTo.getLastColumn()+1,valuesToCopy.length,1).setValues(valuesToCopy);
}
Hope this could help!.
answered Nov 14 '18 at 4:52
shabnam bharmal
1999
1999
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255998%2fadding-a-time-stamp-to-copied-column%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
above/below the row or before/after the column?
– shabnam bharmal
Nov 12 '18 at 4:58
above or below would be best. Right now the column copies into the new sheet next to the previous column.
– Amber Weiand
Nov 14 '18 at 0:56