Forum Discussion

macedosf's avatar
macedosf
Copper Contributor
Mar 02, 2020

Deleting specific row after entering data in another specific cell

Hello guys. 

 

I need some help in order to create a macro which enable user to delete the entire row 4 after entering data in cell A9 in a control spreadsheet

 

My goal is to keep the last five records only in the spreadsheet.

 

Thanks a lot!

4 Replies

  • MisterE's avatar
    MisterE
    Copper Contributor

    macedosf 

     

    I added a macro (macro1) which automatically delete the entire row 4 which is also clickable once they click it. I also made the link non-printable so it doesn't mess up your report if you print it.

    • macedosf's avatar
      macedosf
      Copper Contributor
      Hi Mr E,
      Thank you for your support on this matter.
      Brest Regards!!
  • Riny_van_Eekelen's avatar
    Riny_van_Eekelen
    Platinum Contributor

    macedosf Inspired by the information in this link:

    https://docs.microsoft.com/en-us/office/troubleshoot/excel/run-macro-cells-change 

     

    You could adapt the code like this:

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim KeyCell As Range
    
        Set KeyCell = Range("A9")
    
    If Not Application.Intersect(KeyCell, Range(Target.Address)) _
               Is Nothing Then
    
        Rows("4:4").Select
        Selection.Delete Shift:=xlUp
    
    End If
    End Sub

    ....and place it in the in the code section for the worksheet (i.e. not in a separate module).

    • macedosf's avatar
      macedosf
      Copper Contributor
      Hi,
      Thank you for supporting me on Thais matter.
      Best Regards!!

Resources