如何在不给范围名称命名的情况下选择一个单元格范围? [英] How do I select a range of cells in without giving the range a name?

查看:44
本文介绍了如何在不给范围名称命名的情况下选择一个单元格范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用apps脚本选择单元格C29:Z50作为变量.我希望不必创建一个命名范围(但是如果需要,我可以).

I would like to select cells C29:Z50 as a variable using apps script. I'd prefer not to have to create a named range (but I can if needed).

我的目标是创建一些可以使用内置功能的自定义格式,而不仅仅是颜色.因此,如果单元格B27 =交易",则将C29:Z50格式设置为数字,否则将Z29:Z50格式设置为美元货币.

My goal is to create some custom formatting beyond colors that can use built in functionality. So, if cell B27 = "Transactions" then format C29:Z50 as a number, else format Z29:Z50 as dollar currency.

因此,我不需要单元格的值,只需要单元格组作为变量即可应用于逻辑.

So I don't need the values of the cells, just the group of cells as a variable that I can apply if logic to.

我正在此处阅读文档.

getDataRange()

getDataRange()

返回一个范围,该范围对应于数据所在的维度 当下.这在功能上等同于创建范围限制 通过A1和(Range.getLastColumn(),Range.getLastRow()).

Returns a Range corresponding to the dimensions in which data is present. This is functionally equivalent to creating a Range bounded by A1 and (Range.getLastColumn(), Range.getLastRow()).

文档中的示例抓住了整个选项卡,但我只想要有问题的工作表的一部分.

The example in the documentation grabs the entire tab but I just want a subset of the sheet in question.

我尝试过:

var currency_range = ss.getDataRange(C29, Z50); //"Reference Error. "C29" is not defined."

var currency_range = ss.getDataRange(C29:Z50); // "Missing ) argument list"

如何获取"单元格的范围,以便以后可以根据条件编辑单元格的格式?

How can I "get" the range of cells so that I can later edit their formatting based on if conditional?

推荐答案

您可以使用 Spreadsheet.getRange().例如,这应该起作用:

You can use Spreadsheet.getRange(). For example, this should work:

var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("...");
var currencyRange = ss.getRange("C29:Z250");

好吧,实际上我正在使用 Sheet.getRange ()方法,但在您的情况下,它们应该相同.它提供了更多的方法来声明所需的范围,例如getRange(row, column, numRows, numColumns),这也可能对您有用.

Well, actually I'm using this Sheet.getRange() method instead, but they should be the same in your case. It offers more ways to declare the desired range, such as getRange(row, column, numRows, numColumns), which could be useful for you too.

这篇关于如何在不给范围名称命名的情况下选择一个单元格范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆