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

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Savuti

Board Regular
Joined
Apr 30, 2008
Messages
156
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
 

Savuti

Board Regular
Joined
Apr 30, 2008
Messages
156
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
 

FormR

MrExcel MVP
Joined
Aug 18, 2011
Messages
6,689
Office Version
  1. 365
Platform
  1. Windows
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:

FormR

MrExcel MVP
Joined
Aug 18, 2011
Messages
6,689
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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.
 

Savuti

Board Regular
Joined
Apr 30, 2008
Messages
156
FormR, thank you for the response, the macro works great. Point taken with the patience - got a bit too eager with the project.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,706
Messages
5,833,238
Members
430,199
Latest member
Petty queen

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
Top