0

尝试在 Google 表格中编写一个简单的宏,简单的东西,但我不熟悉该语言;非常沮丧。请帮忙。

我的工作簿中有两个活动工作表,Hotrods 是一个行分隔列表,CarDetail 显示所选行的详细信息...目前我在 Cardetail 中输入 Hotrods 的行号以填写表格。

我正在尝试编写一个将当前Hotrods 行存储在变量中的宏...切换到CarDetail,将Hotrods 中的存储值放入Cell (I,3),然后以Cardetail 为焦点Cell (c,4)而终止。VBA 编辑器不断抛出错误。我错过了一些明显的东西!

请给我一些好的阅读或给我一些好的建议!谢谢

4

1 回答 1

0

我让它工作了......可能不是最干净的代码,但它完成了工作!

function CarDetailForm() {                                      ;
  var fromSheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getName();
  // Should only run from the HotRods sheet 
  if (fromSheet = "HotRods") {                          ;
    var s       = SpreadsheetApp.getActive()             ;
    var ss      = SpreadsheetApp.getActiveSheet()        ;
    // Store HotRods active row number
    var rownum  = ss.getCurrentCell().getRow()           ;
    // Activate the CarDetail sheet
    s.setActiveSheet(s.getSheetByName('CarDetail'), true)  ;
    // activate cell I3 - or it won't work
    s.getRange('I3').activate()                          ;
    // set I3 to the row number carried from HotRods
    s.getCurrentCell().setValue(rownum)                  ;
    // exit macro with cursor in date field of CarDetail
    s.getRange('C4:I4').activate()                       ;
  }                                                      ;
}                                                        ;
于 2018-10-03T18:39:37.717 回答