英文:
Columns Count in Google Sheets? VBA for Example
问题
在JavaScript/Google Sheets中,是否有一种根据列数来设置范围的方法?如果我要调试打印myRange.Address
,它将是$A$4:$M$4
。
Sub testGoogleSheets()
Dim myRange As Range
Set myRange = Range("A4", Cells(4, Columns.Count).End(xlToLeft))
End Sub
英文:
Is there a way in JavaScript/Google Sheets to set a range based on the column count? If i were to Debug.Print myRange.Address it would be $A$4:$M$4.
Sub testGoogleSheets()
Dim myRange As Range
Set myRange = Range("A4", Cells(4, Columns.Count).End(xlToLeft))
End Sub
答案1
得分: 2
这里是脚本:
function adder()
{
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet2');
var yourRange = sheet.getRange("A4");
var yourLastColumn=sheet.getRange("A4:4").getLastColumn();
var yourLastRange=sheet.getRange("A4").offset(0, yourLastColumn-1)
var rsltRange1 = yourLastRange.getNextDataCell(SpreadsheetApp.Direction.PREVIOUS);
Logger.log(rsltRange1.getA1Notation());
var rsltRange2 = sheet.getRange("A4:" + rsltRange1.getA1Notation());
Logger.log(rsltRange2.getA1Notation());
}
英文:
Here the script:
function adder()
{
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet2');
var yourRange = sheet.getRange("A4");
var yourLastColumn=sheet.getRange("A4:4").getLastColumn();
var yourLastRange=sheet.getRange("A4").offset(0, yourLastColumn-1)
var rsltRange1 = yourLastRange.getNextDataCell(SpreadsheetApp.Direction.PREVIOUS);
Logger.log(rsltRange1.getA1Notation());
var rsltRange2 = sheet.getRange("A4:" + rsltRange1.getA1Notation());
Logger.log(rsltRange2.getA1Notation());
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论