If cell length < 3, delete row. For whole column

squidmark

Board Regular
Joined
Aug 1, 2007
Messages
105
I get spreadsheets where previous users "cleared" a cell by using the spacebar. Now, I need some code that will look at all of column G and delete the rows where the cell in column G is blank. But sometimes the "blank" cell is really a space, so it just looks blank.

I've used this:
columns("G").SpecialCells(xlCellTypeBlanks).EntireRow.Delete

to delete the rows that are actually blank. Which is how I realized many aren't actually blank.

Is there a way to just say if len(g1)<2, delete whole row, but have it look at the entire column all at once as the code above does, rather than using something like a for-next loop that will take more time to run?

Yes, I'm a VBA noobie.

Thanks.
 
It's an 'alternate' code for a space, although I don't know much more than that.

See if this works:

Code:
    With Columns("G")
        .Replace what:=Chr(160), replacement:="", lookat:=xlWhole
        .SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    End With

Yep. That did it perfectly. Thanks Weaver!
 
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
No problem.

Are any of your users on Apple Macs? Trying to figure out where the chr(160) got in there
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,702
Members
452,938
Latest member
babeneker

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