【发布时间】:2020-10-15 11:50:15
【问题描述】:
我正在尝试将此宏传递给 Javascript:
Sub Contar_Celdas()
y = Selection.Cells.Count
If ActiveSheet.Name = "TELAS DE SACRIFICIO" Then
Tiempo = y / 4 'Tiempo en horas en telas
MsgBox "El rango tiene " & y & " celdas" & vbCrLf & "Tiempo celdas seleccionadas: " & Tiempo & "
Horas"
Else
Tiempo = y / 2 'Tiempo en horas
MsgBox "El rango tiene " & y & " celdas" & vbCrLf & "Tiempo celdas seleccionadas: " & Tiempo & "
Horas"
End If
End Sub`
主要思想是选择一个通用的单元格范围,脚本会告诉我你选择了多少个单元格,如果是某个工作表,则给我这个数字除以 2,如果是其他工作表,则除以 4,
这是我的第一次尝试,但它不起作用。
function Contar_Celdas() {
var app= SpreadsheetApp;
var activeSheet = app.getActiveSpreadsheet().getActiveSheet(); // Returns de active sheet
var time; // Declare the variable time
var activeRange =activeSheet.getActiveRange().length; // Returns de active range selected on the active sheet
Logger.log(activeSheet); //
Logger.log(activeRange); //
if (activeSheet == 'TELAS DE SACRIFICIO') { // If the name of the active sheet is igual to " TELAS DE SACRFICIO"
time = activeRange / 4;// Return the time in the sheet " TELAS DE SACRIFICIO"
Browser.msgBox('El rango tiene'+ activeRange + 'celdas '+ '\\n' +'Tiempo de celdas seleccionadas:' + time); //Shows in a message the range selected and the number of cell divided by 4
} else {
time = activeRange/2 ;// Return the time in the rest of active sheets that are not "TELAS DE SACRFICIO"
Browser.msgBox('El rango tiene'+ activeRange + 'celdas '+ '\\n' +'Tiempo de celdas seleccionadas:' + time);//Shows in a message the range selected and the number of cell divided by 2
}
}
提前致谢。 哈维尔
【问题讨论】:
-
是的,我试过了,但我没有找到信息,这就是我的原因,谢谢你的帮助
-
您是否与
console.log()核对过每一步返回的内容?number_of_cells_selected返回一个范围。以下是Range 的操作 -
是的,我已经检查过了,似乎我没有很好地定义变量,我已经更改了代码,它没有返回我的范围。
标签: javascript excel google-sheets