VBA Delete Row if ....

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,124
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I'm working with a database where the first Column A's cell is not blank starting in row 11 of the worksheet.

I'm trying to create a Sub to delete the row if there are no values in the proceeding Column A.

For example, If Column A is not empty BUT its Columns B to AK are empty, the sub will delete that row.

Capture1.PNG


Above there are values in Column A but if there are no values in that row from Columns B to AK, the sub will delete that row, as can be seen below.

Capture2.PNG



So here the sub will delete the rows 15-16, 18-36 ...., because there were no values in that row from Columns B to AK, so the sub will delete that row.

Please let me know, if you can provide me with a sub to test out!

Thank you!
Pinaceous
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi Pin
Did you try the code I posted ?
With regard to the code @Cubist posted, it will always have issues because you are running the loop from top to bottom, so it will skip rows when one is deleted. You must always loop from bottom to top when deleting rows
Hi Michael M!

My oversight my apologies! Yes, it works very well but do you know if you can delete the row specifically between A:AI, only and not the entire length of the row as I previously mentioned?
Other than that your code works great!

Thank you!
pinaceous
 
Upvote 0
Replace rows(r).delete
With
Range("A" & r & ":AI" & r).delete
 
Upvote 1
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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