简体   繁体   English

将公式应用于整列

[英]Apply formula to the entire column

I'm changing all the zip codes from Column A into Column B with the formula:我正在使用以下公式将 A 列中的所有 zip 代码更改为 B 列:

=TEXT(A1,"00000")

Like this:像这样:

在此处输入图像描述

I want every cell in Column B to be transformed using the formula above.我希望使用上面的公式转换 B 列中的每个单元格。 But I have over 40,000 rows, so it is not feasible to drag the formula down to apply it to the entire Column B because it takes so long.但是我有超过 40,000 行,所以将公式向下拖动以将其应用于整个 B 列是不可行的,因为它需要很长时间。

Are there any alternatives to dragging?除了拖动还有其他选择吗?

It looks like some of the other answers have become outdated, but for me this worked:看起来其他一些答案已经过时了,但对我来说这很有效:

  1. Click on the cell with the text/formula to copy单击带有文本/公式的单元格进行复制
  2. Shift+Click on the last cell to copy to Shift+单击要复制到的最后一个单元格
  3. Ctrl + Enter Ctrl + Enter

(Note that this replaces text if the destination cells aren't empty) (请注意,如果目标单元格不为空,这将替换文本)

I think it's a more recent feature, but it works for me:我认为这是一个更新的功能,但它对我有用:

Double clicking the square on the bottom right of the highlighted cell copies the formula of the highlighted cell.双击突出显示单元格右下角的方块会复制突出显示单元格的公式。

Hope it helps.希望能帮助到你。

I think you are in luck.我认为你很幸运。 Please try entering in B1:请尝试输入B1:

=text(A1:A,"00000")

(very similar!) but before hitting Enter hit Ctrl + Shift + Enter . (非常相似!)但在按 Enter之前按 Ctrl + Shift + Enter

This worked for me:这对我有用:

  • Input the formula in the first cell.在第一个单元格中输入formula
  • Press Enter .Enter
  • Click on the first cell and press Ctrl + Shift + down_arrow .单击第一个单元格,然后按Ctrl + Shift + down_arrow This will select the last cell in the column used on the worksheet.这将选择工作表上使用的列中的最后一个单元格。
  • Ctrl + D . Ctrl + D。 This will fill copy the formula in the remaining cells.这将填充复制剩余单元格中的公式。

This is for those who want to overwrite the column cells quickly (without cutting and copying).这适用于那些想要快速覆盖列单元格(无需剪切和复制)的人。 This is the same as double-clicking the cell box but unlike double-clicking, it still works after the first try.这与双击单元格框相同,但与双击不同的是,它在第​​一次尝试后仍然有效。

  1. Select the column cell you would like to copy downwards选择要向下复制的列单元格
  2. Press Ctrl + Shift + to select the cells belowCtrl + Shift + 选择下面的单元格
  3. Press Ctrl + Enter to copy the contents of the first cell into the cells belowCtrl + Enter将第一个单元格的内容复制到下面的单元格中

BONUS:奖金:

The shortcut for going to the bottom-most content (to double-check the copy) is Ctrl + .转到最底部内容(仔细检查副本)的快捷方式是Ctrl + To go back up you can use Ctrl + but if your top rows are frozen you'll also have to press Enter a few times.要返回,您可以使用Ctrl + 但如果您的顶行被冻结,您还必须按Enter几次。

For Mac:对于 Mac:

Click on the first cell having the formula and press Ctrl + Shift + down_arrow.单击具有公式的第一个单元格,然后按 Ctrl + Shift + down_arrow。 This will select the last cell in the column used on the worksheet.这将选择工作表上使用的列中的最后一个单元格。


Command + D


(don't use ctrl) . (不要使用 ctrl) This will fill the formula in the remaining cells.这将在剩余单元格中填充公式。

Let's say you want to substitute something in an array of string and you don't want to perform the copy-paste on your entire sheet .假设您想替换字符串数组中的某些内容,并且不想在整个工作表上执行复制粘贴

Let's take this as an example:让我们以此为例:

  • String array in column "A": {apple, banana, orange, ..., avocado} “A”列中的字符串数组:{apple,banana,orange,...,avocado}
  • You want to substitute the char of "a" to "x" to have: {xpple, bxnxnx, orxnge, ..., xvocado}您想将“a”的字符替换为“x”以具有: {xpple, bxnxnx, orxnge, ..., xvocado}

To apply this formula on the entire column (array) in a clean an elegant way, you can do:要以简洁优雅的方式将此公式应用于整个列(数组),您可以执行以下操作:

=ARRAYFORMULA(SUBSTITUE(A:A, "a", "x"))

It works for 2D-arrays as well, let's say:它也适用于二维数组,比方说:

=ARRAYFORMULA(SUBSTITUE(A2:D83, "a", "x"))

Found another solution:找到另一个解决方案:

  • Apply the formula to the first 3 or 4 cells of the column将公式应用于列的前 3 或 4 个单元格
  • Ctrl + C the formula in one of the last rows (if you copy the first line it won't work) Ctrl + C最后一行中的公式(如果复制第一行它将不起作用)
  • Click on the column header to select the whole column单击列标题以选择整列
  • Press Ctrl + V to paste it in all cells bellowCtrl + V将其粘贴到下面的所有单元格中

Just so I don't lose my answer that works:只是这样我就不会失去有效的答案:

  1. Select the cell to copy选择要复制的单元格
  2. Select the final cell in the column选择列中的最后一个单元格
  3. Press CTRL + DCTRL + D

You can use Ctrl+Shift+Down+D to add the formula to every cell in the column as well.您也可以使用 Ctrl+Shift+Down+D 将公式添加到列中的每个单元格。

Simply click/highlight the cell with the equation/formula you want to copy and then hold down Ctrl+Shift+Down+D and your formula will be added to each cell.只需单击/突出显示要复制的方程式/公式的单元格,然后按住 Ctrl+Shift+Down+D,您的公式就会添加到每个单元格中。

The exact formula is:确切的公式是:

=ArrayFormula(text(A1:A,"00000"))

ArrayFormula works on multiple rows (in the above example, every row), and results are placed in the cell with the formula and the cells below it in the same column. ArrayFormula适用于多行(在上面的示例中,每一行),结果放置在具有公式的单元格中,并且在同一列中放置在它下面的单元格中。 It looks as if the same formula was copied into all those rows.看起来好像相同的公式被复制到所有这些行中。

If any of the cells in that column are not empty, they won't get overwritten.如果该列中的任何单元格不为空,则它们不会被覆盖。 Instead, you will get an error message.相反,您将收到一条错误消息。

To save yourself typing, you can use the trick from the answer above by pnuts :为了节省自己的打字时间,您可以使用pnuts上面答案中的技巧:

Type: =text(A1:A,"00000") and then hit the following key combination:键入: =text(A1:A,"00000")然后按以下组合键:

  • On windows: Ctrl + Shift + Enter在 Windows 上: Ctrl + Shift + Enter

  • On a MAC: Command + Shift + Enter在 MAC 上: Command + Shift + Enter

This will convert the formula to ArrayFormula .这会将公式转换为ArrayFormula

After hitting the key combination, you need to hit Enter, to actually apply the converted formula.点击组合键后,您需要按 Enter,才能实际应用转换后的公式。

If your sheet contains header row(s), and you want to apply formula from (for example) row 5 on, you would use =text(A5:A,"00000") instead.如果您的工作表包含标题行,并且您想从(例如)第 5 行应用公式,则可以改用 =text(A5:A,"00000")。

This answer includes information from pnuts 's answer and LOAS 's comment.此答案包括来自pnuts的答案和LOAS的评论的信息。

To be clear when you us the drag indicator it will only copy the cell values down the column whilst there is a value in the adjacent cell in a given row.要清楚,当您使用拖动指示器时,它只会将单元格值复制到列中,而给定行中的相邻单元格中有一个值。 As soon as the drag operation sees an adjacent cell that is blank it will stop copying the formula down.一旦拖动操作看到相邻的单元格为空白,它将停止向下复制公式。

.eg 。例如

1,a,b
2,a
3,
4,a

If the above is a spreadsheet then using the double click drag indicator on the 'b' cell will fill row 2 but not row three or four.如果上面是电子表格,则使用“b”单元格上的双击拖动指示器将填充第 2 行,但不会填充第 3 或第 4 行。

Well, Another easiest and simplest way is as in my file rows were above 16000, which is pretty huge number.好吧,另一种最简单最简单的方法是在我的文件中的行数超过 16000,这是一个非常大的数字。 So steps which helped me are:所以帮助我的步骤是:

1. Select the cell in which formula is written. 1.选择写入公式的单元格。
2. Then go to NameBox (it is the box which tells about active cell). 2.然后转到NameBox (它是告诉活动单元格的框)。 Here in my case it was the cell where was formula was written(ie P2).在我的例子中,这是编写公式的单元格(即 P2)。
3. Then in that cell type your active cell number:your last row .For example last row of my column was 16745 and formula was written in P2 . 3.然后在该单元格中输入您的活动单元格编号:您的最后一行。例如,我的列的最后一行是 16745公式写在 P2 中 So write P2:P16745 ,所以写P2:P16745
4. Press Enter in Name Box and bingo your whole area of column till last row is selected. 4.在名称框中按 Enter 并宾果游戏整个区域,直到最后一行被选中。
5. Now press Ctrl+D (Windows) 5.现在按Ctrl+D (Windows)

Lambda Solution Lambda解决方案

Using the new LAMBDA and MAP functions, this is now doable without an ArrayFormula or having to drag anything.使用新的LAMBDAMAP函数,现在无需ArrayFormula或拖动任何东西就可以实现。

=MAP(A2:A6, LAMBDA(value, TEXT(value, "00000")))
  • LAMBDA defines a function. LAMBDA定义了一个 function。 value is the parameter, which we can use in the formula expression. value是参数,我们可以在公式表达式中使用。
  • MAP applies the LAMBDA to each value in the given range. MAPLAMBDA应用于给定范围内的每个值。 This also works on 2D ranges.这也适用于 2D 范围。

try:尝试:

=INDEX(TEXT(A2:A; "00000"))

advantages: short, works, smells nice优点:短,好用,好闻

to map out empty cells you can do:到 map 空单元格你可以这样做:

=INDEX(IF(A2:A="";;TEXT(A2:A; "00000")))

You may fill the column by double-clicking on the bottom right hand corner of the cell which you want to copy from (the point on the box that you would otherwise drag) and it will be applied to whole column.您可以通过双击要从中复制的单元格的右下角来填充该列(否则您将拖动框上的点),它将应用于整个列。

NB: This doesn't work if you have the filter applied, nor if there is already something already in the cells below.注意:如果您应用了过滤器,或者下面的单元格中已经存在某些内容,这将不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM