在Google表格中查找最后一行 [英] Find Last Row in Google Sheets
问题描述
我发现Google表格的宏元素比VBA困难得多.我想尝试计算最后占用的行.然后,我想显示一条值为lr的消息.在VBA中,我本可以在几分钟内完成此操作.
I am finding the macro element of Google Sheets considerably more difficult than VBA. I want to try and calculate the last occupied row. And then I wanted to be shown a message with the value of lr. In VBA, I could have done this in minutes.
function Test() {
var ss = Spreadsheetapp.getactivespreadsheet().getActiveSheet();
var lr = ss.getLastRow();
Browser.msgBox(lastRow);
}
我收到错误消息 ReferenceError:Spreadsheetapp未定义
,我不是很了解.我在StackOverflow上看到了有关此问题的其他文章,但无法理解提供的答案.
I am getting the error message ReferenceError: Spreadsheetapp is not defined
which I don't really understand. I have seen some other posts about this issue on StackOverflow but failed to understand the answers provided.
更新
在安迪(Andi)在下面发表评论之后,我有了另一番眼神,并将代码更改为 var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
.现在就可以了.
After Andi commented below I had another look and changed my code to var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
. And now it works.
推荐答案
简单的解决方案,伙计.它是SpreadsheetApp,而不是电子表格应用.大写A.
Simple solution, man. It's SpreadsheetApp, not spreadsheetapp. Capitalize the A.
由于脚本正在寻找名为Spreadsheetapp的变量,该错误不存在.
It's giving you that error because the script is looking for a variable named Spreadsheetapp, which doesn't exist.
此外,由于与上述相同的原因,它是getActiveSpreadsheet()而不是getactivespreadsheet().
Also, it's getActiveSpreadsheet() and not getactivespreadsheet() for the same reason as above.
https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app
这篇关于在Google表格中查找最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!