I have and excel spreadsheet and I need to make a button that deletes the entire row in which the button is located.

Lets say I have a button on cell G7. When I press it, I want the entirety of row 7 to be deleted and everything under that shifted up.

This can be easily hardcoded to delete row 7, but I want to have a button located on every row up to ~30, so at G1, G2, G3,..., G30, and when I press it, I want it to only delete the row on which it is located. Example: I press a button on G7, everything under row 7 is shifted up, so row 8 becomes row 7 and so on. I then press button at G9, and I want row 9 (not 10, which it used to be before first pressing button at G7) to be deleted.

Is is possible to do this?


have the button execute based on its topleftcell.row

s = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row will give you the row number as s so just plug it into where your deletion is

using application.caller you should be able to have all buttons execute the same macro, but I'm not 100%. Check the reference here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.