[英]Excel formula that turns cells into empty cells if the cell next to it is already empty
I need a formula in excel that turns the cells in column D empty if the corresponding cell in column C (ie on the same row) is already empty. 我需要一个excel中的公式,如果C列中的相应单元格(即同一行)已经为空,则将D列中的单元格为空。
To elaborate, this is a sample from my excel sheet: 详细来说,这是我的Excel工作表中的示例:
C D
1 0,5 500
2 0.3 400
3 600
4 700
5 3.1 400
6 350
7 1.1 400
I want it to turn into this: 我希望它变成这样:
C D
1 0,5 500
2 0.3 400
3
4
5 3.1 400
6
7 1.1 400
All the values are hard coded. 所有值都是硬编码的。 Is what I want possible?
我想要什么?
Not sure what you have in D1 to already create value etc. 不确定您在D1中拥有什么来创造价值等。
But try: 但是尝试:
=IF(C1="","", Your original value/formula here )
Pretty sure you can't use a formula in this case. 可以肯定,在这种情况下您不能使用公式。 What you need is a macro
您需要的是一个宏
Sub EmptyCells()
For Counter = 1 To 20
Set cell = Worksheets("Sheet1").Cells(Counter, 2)
If IsEmpty(cell.Value) = True Then
Worksheets("Sheet1").Cells(Counter, 3).Value = ""
End If
Next
End Sub
You can call the vba editor with alt+F11. 您可以使用alt + F11调用vba编辑器。 Right click your sheet and select Insert->Module.
右键单击工作表,然后选择“插入”->“模块”。 Paste the code in there and save the excel as .xlsm file.
将代码粘贴到此处,并将excel保存为.xlsm文件。 Open the macro view with alt+F8 and run your macro.
使用alt + F8打开宏视图,然后运行宏。
After you run the macro all values from column D that have an empty Value in column C will be empty too. 运行宏后,来自D列的所有值在C列中都为空。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.