VBA deletes row and it causes the lower rows to shift up

kiaheyrati038

New Member
Joined
Dec 3, 2021
Messages
3
Office Version
  1. 2021
Platform
  1. Windows
this code works great and deletes empty rows and shifts things up

VBA Code:
sub test()
with range("L12:L28")
for i=.rows.count to 1 step -1
if isempty(.cells(i,1)) then .rows(i).delete shift:=xlup
next
end with
end sub

But the problem is that it also shifts anything below the L28 up and it ruins the rest of my file. any idea to just move the values up instead of shifting the whole row up and screwing the rest of worksheet?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi & welcome to MrExcel.
You could clear the contents of those rows & then sort the data so the blank rows move to the bottom.
 
Upvote 0
Hi and thanks. but if i clear the content of those rows then there's nothing left to sort! though sorting scrambles my data and i can't do it anyways
 
Upvote 0
In that case every time you delete a row, you will need to insert another in row 29
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,244
Members
452,622
Latest member
Laura_PinksBTHFT

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
Back
Top