Vegard Dyran
Vegard Dyran

Reputation: 79

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 (i.e. on the same row) is already empty.

To elaborate, this is a sample from my excel sheet:

   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?

Upvotes: 0

Views: 122

Answers (2)

user2542935
user2542935

Reputation: 11

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. Right click your sheet and select Insert->Module. Paste the code in there and save the excel as .xlsm file. Open the macro view with alt+F8 and run your macro.

After you run the macro all values from column D that have an empty Value in column C will be empty too.

Upvotes: 1

PeterH
PeterH

Reputation: 1040

Not sure what you have in D1 to already create value etc.

But try:

=IF(C1="","", Your original value/formula here )

Upvotes: 2

Related Questions