[英]Automatically calculate (or delete) rows in Excel when first column is changing
I have a big table, where first columns X is "input column" and range it's changing.我有一个大表,其中第一列X是“输入列”并且范围正在改变。
Y - There are more formulas and functions (Vlookup) and 1st column X is a lookup value, and then other columns are calculated from other sheets. Y - 有更多的公式和函数(Vlookup),第 1 列 X 是查找值,然后从其他工作表计算其他列。
| A | B | C | D | E
1 | X | Y | Y | Y | Y
2 | X | Y | Y | Y | Y
3 | X | Y | Y | Y | Y
4 | X | Y | Y | Y | Y
I am inserting (and deleting) more X values (actual data) and then I use "double click" for all other Y columns to be calculated, BUT it's not good because the X range is not the same.我正在插入(和删除)更多 X 值(实际数据),然后我对所有其他要计算的 Y 列使用“双击”,但这并不好,因为 X 范围不相同。 I tried to convert it to table "Ctrl-T", but it's not working very good for me.我试图将它转换为表“Ctrl-T”,但它对我来说效果不佳。 Maybe I don't use it properly.也许我没有正确使用它。
Problem:问题:
If I paste a new X column, I need other Y columns to be automatically calculated OR if I delete few X rows, other Y should be also deleted.如果我粘贴一个新的 X 列,我需要自动计算其他 Y 列,或者如果我删除几个 X 行,其他 Y 也应该被删除。 Now I get something like this:现在我得到这样的东西:
| A | B | C | D | E
1 | X | Y | Y | Y | Y
2 | X | Y | Y | Y | Y
3 | | N/A | N/A | N/A | N/A
4 | | N/A | N/A | N/A | N/A
or:或者:
| A | B | C | D | E
1 | X | Y | Y | Y | Y
2 | X | Y | Y | Y | Y
3 | X | | | |
What I need:我需要的:
If I remove X value I need automatically disappear Y values:如果我删除 X 值,我需要自动消失 Y 值:
| A | B | C | D | E
1 | X | Y | Y | Y | Y
2 | X | Y | Y | Y | Y
If I add X value I need automatically calculate Y values:如果我添加 X 值,我需要自动计算 Y 值:
| A | B | C | D | E
1 | X | Y | Y | Y | Y
2 | X | Y | Y | Y | Y
3 | X | Y | Y | Y | Y
Hope it's clear, thank you!希望清楚,谢谢!
对于 Y 列,您可以添加“IF”FORMULA
=if(A1>0,*Y COLUMN FORMULA*,"")
try changing formula to尝试将公式更改为
=iferror(*Y formula,"")
or if it's still slow and if you are changing only X Columns或者如果它仍然很慢并且您只更改 X 列
you can use below code你可以使用下面的代码
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 And Target.Count = 1 Then 'CHECK IF THERE IS ANY CHANGE ON X COLUMN
If Target.Value = Empty Then 'CHECK IF X COLUMN HAS BEEN DELETED
Rows(Target.Row).Delete 'IF X COLUMN IS DELETED, DELETS WHOLE ROW
Else
Cells(Target.Row - 1, 2).Resize(1, 4).Copy Cells(Target.Row, 2).Resize(1, 4) 'IF X COLUMN IS ENTERED OR MODIFIED COPIES ABOVE Y COLUMN FORMULAS
End If
End If
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.