PDA

View Full Version : Sorting Columns



selkov
04-12-2007, 01:11 PM
I have a spreadsheet that is populated my Concatinating data from other worksheets. Some of the results are numbers, some is data while others are blank spaces and othersare set by the concactenating default of "" when the criteria is not met. I need to sort these colums. However it seems that the default "" from the formula is not a BLANK or a ZERO or an empty cell.
Those cells will place themselves at the top of the sort. I need to eliniate them. I have copied and pasted as values but that has no effect. Ironically I can identify the cells with an if statement so what I need help with is generating a macro that will cycle thru the range of results and delete the approriate cells.
I have tried the following:
lr = Range("A1").End(xlDown).Row ' Last Row
lc = Range("A1").End(xlToRight).Column ' Last Column
For Each cell In Range(Cells(1, 1), Cells(lc, lr))
cell.Select
AC = ActiveCell
If AC = "" Then Selection.Delete Shift:=xlUp
Next
But this does not work as it cycles top to bottom and leaves behind 1/2 the problem cells.
Any Ideas Are Welcome.

lucas
04-12-2007, 01:21 PM
lr = Range("A1").End(xlUp).Row ' Last Row

mdmackillop
04-12-2007, 02:31 PM
lr = Range("A1").End(xlUp).Row ' Last Row

Too much caffiene. Have a beer instead!

mdmackillop
04-12-2007, 02:34 PM
Sub GetRidOfBlanks()
Cells(1, 1).CurrentRegion.SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp
End Sub

or, if that doesn't work, try

Sub GetRidOfBlanks2()
Dim cel as Range
For Each cel In Cells(1, 1).CurrentRegion
cel.Formula = Trim(cel.Formula)
Next
Cells(1, 1).CurrentRegion.SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp
End Sub

lucas
04-12-2007, 05:33 PM
Yep, I'm a little distracted today....