I suspect that a third-party application or browser plug-in is interfering with the Windows clipboard and causing your problem.
Whatever the issue is, you may be able to quickly accomplish your copy/paste goal by using the Web Clipboard tool inside of Google Docs. (Look for the collapsible section called "The web clipboard tool".) The directions are not well written, though. Basically, select A2:A7, click Edit/Web clipboard/Copy. Select your destination cell. Click Edit/Paste (or Paste Special if you prefer. In fact, a few years ago I had a copy/paste issue that I could only resolve by using Paste Special but I cannot remember the details).
Because the Web clipboard goes through the Google server, if it does not work, then submit a bug report.
I believe it will work, though. If it does work, you can troubleshoot the cause of the problem by attempting the same action on another computer, on the same computer but in a different browser, on the same computer but with all background programs disabled (especially anything that looks at your clipboard such as anti-virus, screen capture, MS Office, or a clipboard manager), same browser but with plugins disabled, and/or copy the cells and then paste into notepad (it should put the data on six lines. I thought of at least one more troubleshooting idea but it's 2 am and I forgot it while I was writing the list. Oops. Try opening and editing the spreadsheet in LibreOffice or some other spreadsheet software.
I'm also curious what would happen if instead of selecting only B2, you selected B2:B7 and then pasted.
A potential problem is if you have multiple languages and keyboard inputs installed on your computer. When Windows switches from left-to-right languages to RTL languages, whitespace characters often do crazy things. So, you probably want to avoid selecting Arabic or other RTL languages while editing. If you have MS Maren or the language bar enabled, they might mess with you, too.
In the spreadsheet, is there anything in Script Manager?
I'm either out of ideas or too tired to think of more things. Good luck!
First, the error: shs
is an array, since you populate it with ss.getSheets()
, so it doesn't have a method getActiveCell()
. However, the elements of the array has that method.
You are also referencing a variable sheet
, which you haven't defined anywhere.
Currently, your code is more suitable for going through a single sheet, you need to iterate through the shs
array to have it operate on all sheets.
The following function will go through all cells in all sheets:
function onEdit(event){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var shs = ss.getSheets(), num = shs.length;
var sheetName = []
for (var sheetIdx = 0; sheetIdx < shs.length; sheetIdx++) {
var sheet = shs[sheetIdx];
for(var i = 1; i<num; i++) {
...
}
}
But you wanted to skip the first sheet, so let's start with element 1
in the array (since the array is 0
-based, element 1
is the second sheet):
function onEdit(event){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var shs = ss.getSheets(), num = shs.length;
var sheetName = []
for (var sheetIdx = 1; sheetIdx < shs.length; sheetIdx++) {
var sheet = shs[sheetIdx];
for(var i = 1; i<num; i++) {
var editedCell = shs.getActiveCell();
var columnToSortBy = 1;
var tableRange = "A2:G99"; // What to sort.
if(editedCell.getColumn() == columnToSortBy){
var range = sheet.getRange(tableRange);
range.sort( { column : columnToSortBy, ascending: false });
}
}
}
}
As for your comment, your code
function onEdit(event) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
for (var n in ss.getSheets()) {
var sheet = ss.getSheets()[n];
var name = sheet.getName();
if (name == 'Dashboard')
return;
var editedCell = ss.getActiveCell();
var columnToSortBy = 1;
var tableRange = "A2:G99";
if (editedCell.getColumn() == columnToSortBy) {
var range = sheet.getRange(tableRange);
range.sort({column: columnToSortBy, ascending: false});
}
}
}
could work, if you replace return
with continue
. You don't want return
, it ends the script. continue
skips to the next element in the for
loop.
Best Answer
Whenever an argument is a range containing more than one cell, the custom function receives a 2D array. For example, suppose this is your spreadsheet.
Then:
myFunc(A1:B2)
receives[[5,7],[6,8]]
myFunc(A1:B1)
receives[[5,7]]
myFunc(A1:A2)
receives[[5],[6]]
- single-cell rows are still given as arrays.myFunc(A1)
receives5
(a single cell is not given as an array).So, the first order of business would be to standardize these so that everything is represented by a 1D array. Like this:
Then your function could use the special
arguments
object to handle the unknown number of arguments. In my example, allCells is a 1D array containing the values of all cells involved. For demonstration, I have it returned as a comma-separated string.For example,
myFunc(A1:B2, A1:A2, B2)
returns the string "5,7,6,8,5,6,8".