need a tweak for a delete rows macro

kualjo

Board Regular
Joined
Aug 15, 2006
Messages
118
Office Version
  1. 365
Platform
  1. Windows
I got the following code from another thread, but need to make a small change to better fit my need. The assumption of this code is that entire rows are blank. It works in column A, but I need it to work in whatever column I have selected. Sometimes, I have blank cells on rows where other data resides, but it's OK to kill the other data in order to be rid of the blanks. How can I change the following code to work in whatever column I have selected?

Notes:
1 - I can't sort by the blanks, then delete those rows, because the data needs to remain in its output sequence.
2 - Outside of this bit of code, I have a column variable that identifies the selected column (col = ActiveCell.Column).
3 - I tried changing the "A" to something else, but it still continued to work on column A.

Code:
For i = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
    If cells(i, 1).Value = "" Then cells(i, 1).EntireRow.Delete
Next i

I know the answer is probably very obvious, but I'm just not seeing it.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Try

Code:
For I = Cells(Rows.Count, ActiveCell.Column).End(xlUp).Row To 1 Step -1
    If Cells(I, ActiveCell.Column).Value = "" Then Rows(I).Delete
Next I
 
Upvote 0
That's it! And in order to tighten it up just a little more, I substituted my col variable for ActiveCell.Column. Small difference, but I have what I need. Thanks so much!
 
Upvote 0

Forum statistics

Threads
1,224,565
Messages
6,179,549
Members
452,927
Latest member
rows and columns

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