在Google表格中的列数?以VBA为例

huangapple go评论68阅读模式
英文:

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

在Google表格中的列数?以VBA为例

答案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());

 }  

huangapple
  • 本文由 发表于 2020年1月6日 23:22:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/59614652.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定