Home » excel » ms office – Creating a button that deletes specific cells and shift row up if cell value is empty or zero in MS excel

ms office – Creating a button that deletes specific cells and shift row up if cell value is empty or zero in MS excel

Posted by: admin May 14, 2020 Leave a comment

Questions:

I am trying to create a button in excel spreadsheet which can delete the 4 cells in a row and shifts the bottom 4 cells up if value in specific cell is zero or empty.I have worked in other languages and i know basic excel formulas but I don’t know much about VBA. and i am not sure if stack overflow if right place fr ms office discussion.

How to&Answers:

Here is a good article to look at: https://analysistabs.com/vba-code/range/m/delete/

Could you provide some more details? For example, if A1 = 0, then delete A2:A4 and shift up?

If A1 = 0 Then 
  Range("A2:A4").Delete Shift:=xlToUp

If you’re looking for the button to only work on the cell that you’re currently selecting, you could try:

If ActiveCell = 0 Then
  Range(ActiveCell.Offset(0,1), ActiveCell.Offset(0,4)).Delete Shift:=xlToUp