macro to delete cell value above row that is deleted

Savuti

Board Regular
Joined
Apr 30, 2008
Messages
156
Hello, when a row is deleted on the spreadsheet I need the value in the cell in column "D" immediately above the deleted row to be deleted.

Is this possible
Thanks
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Can someone tell me if what I am asking is even possible. I have tried a few methods but end up deleting a whole bunch of things that I don't want to. This is the last thing I need for the spreadsheet - help is much appreciated.

Thanks
 
Upvote 0
Please can someone help with this - as I said, is it even possible to do this. If not I will have to try something else.

Thanks
 
Upvote 0
This will still clear the cell in column D if the entire rows content is cleared as well as deleted - maybe it is close enough for what you are trying to achieve.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i as Long
If Target.Address = Target.EntireRow.Address Then
    Application.EnableEvents = False
        For i = 1 To Target.Areas.Count
            If Target.Areas(i).Row > 1 Then
                If Evaluate("=COUNTA(" & Target.Areas(i).Address & ")") = 0 Then
                    Range("D" & Target.Areas(i).Row - 1).ClearContents
                End If
            End If
        Next i
    Application.EnableEvents = True
End If
End Sub
 
Last edited:
Upvote 0
Please can someone help with this - as I said, is it even possible to do this. If not I will have to try something else.

BTW - You should try to be a little more patient, it's a little off putting for some people if you keep bumping your threads every hour/half hour or so.
 
Upvote 0
FormR, thank you for the response, the macro works great. Point taken with the patience - got a bit too eager with the project.
 
Upvote 0

Forum statistics

Threads
1,218,899
Messages
6,145,091
Members
450,590
Latest member
Naneng

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top