简体   繁体   English

Excel公式,如果旁边的单元格已经为空,则将单元格转换为空单元格

[英]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.

相关问题 Excel公式的日期,但不包括空单元格 - Excel Formula for Dates, But Excluding Empty Cells Excel - 用于跳过空单元格的数组公式 - Excel - Array Formula to skip empty cells EXCEL VBA-遍历一行中的单元格,如果不为空,则将单元格值复制到另一行,直到下一行不为空 - EXCEL VBA - Loop through cells in a row, if not empty, copy cell value into another row until next row not empty Excel - 计算列中的空单元格,直到找到非空单元格报告然后继续向下列直到找到下一个非空单元格 - Excel - Count Empty Cells in a Column until a Non Empty Cell is Found Report then Continue down column till next non empty cell is found 在Excel中删除空单元格 - Remove empty cells in Excel ElseIf 公式检查单元格是否为空,如果是则空白其他单元格 - ElseIf formula to check if cell is empty and if so to blank out other cells Excel公式返回唯一记录(空单元格除外) - Excel formula returning unique records except empty cells Excel公式将A列和B列的值转移到C和D空单元格 - Excel Formula to shift value of Column A and B to C and D empty cells Excel 公式将交货日期和目标日期与空单元格进行比较 - Excel formula to compare delivery date and target date with empty cells Excel VBA-用可变范围公式填充空的数据库单元格 - Excel VBA - Fill in empty database cells with variable range formula
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM