Forum Discussion

Excel's avatar
Excel
Iron Contributor
Jul 29, 2021
Solved

Question related to VBA

Hello Everyone,

 I am trying to remove one single row above the active cell, is there a VBA code for the same? For example i may be in cell B66 or F15. If i have to delete the entire row immediately above the active cell, is there a vba code that i can use to make it dynamic?

 

Please help..??

  • Excel 

    LONG is the numerical data type and Dim r AS LONG means the variable r will hold the numerical value.

    I could write the code without declaring any variable but I did it to make it easy for you to follow so that you can tweak it yourself if required.

     

    Alternatively, you may try one line of code to do this...

    Sub DeleteRows()
    Rows(ActiveCell.Row - 1).Delete
    End Sub

     

    If that takes care of your original question, please take a minute to accept the post with the proposed solution as a Best Response to mark your question as Solved.

7 Replies

    • Excel's avatar
      Excel
      Iron Contributor
      Thank you so much sir😊😊
  • Excel 

    You may try something like this...

    The following code will delete the row from the ActiveSheet.

     

    Sub DeleteRow()
    Dim r As Long
    r = ActiveCell.Row - 1
    Rows(r).Delete
    End Sub

     

    • Excel's avatar
      Excel
      Iron Contributor
      Sir, why we use LONG as declaration?
      What is the use of LONG in VBA code?
      • Subodh_Tiwari_sktneer's avatar
        Subodh_Tiwari_sktneer
        Silver Contributor

        Excel 

        LONG is the numerical data type and Dim r AS LONG means the variable r will hold the numerical value.

        I could write the code without declaring any variable but I did it to make it easy for you to follow so that you can tweak it yourself if required.

         

        Alternatively, you may try one line of code to do this...

        Sub DeleteRows()
        Rows(ActiveCell.Row - 1).Delete
        End Sub

         

        If that takes care of your original question, please take a minute to accept the post with the proposed solution as a Best Response to mark your question as Solved.