owentmoore
Technical User
Hi all
I have a module that searches column A for non blank cells and deletes the non blanks (it needs to do this one by one as it's part of a larger routine, selecting the entire column and deleting isn't an option).
The code is as follows:
The code works well for a number of deletions and then stops on a blank cell which it shouldn't do. In the example below it stops on cell A19 even though cell A21 below it contains a value. Another point, after I end the routine, if I manually select and clear the contents of the cells cleared during the routine. Then when I rerun the macro it finds and deletes the last value in cell A21!!
A1
A2
A3
A4
A5
A6
A7
A8 1.25
A9
A10 14.50
A11
A12
A13
A14 0.25
A15
A16 15.00
A17 13.50
A18 0.50
A19
A20
A21 0.83
I am totally at a loss as to why it isn't finding and deleting cell A21 when the macro is run first.
Please help.
Owen
I have a module that searches column A for non blank cells and deletes the non blanks (it needs to do this one by one as it's part of a larger routine, selecting the entire column and deleting isn't an option).
The code is as follows:
Code:
Sub FindAndeDeleteNonBlanks()
' Find the first filled cell in column A1
Range("A1").End(xlDown).Select
' Loop finding and deleting fiiled cells until all non-blank cells deleted
Do Until ActiveCell.Value = ""
'Find the first used cell in a column
Range("A1").End(xlDown).Select
Selection.ClearContents
Range("A1").End(xlDown).Select
Loop
End Sub
The code works well for a number of deletions and then stops on a blank cell which it shouldn't do. In the example below it stops on cell A19 even though cell A21 below it contains a value. Another point, after I end the routine, if I manually select and clear the contents of the cells cleared during the routine. Then when I rerun the macro it finds and deletes the last value in cell A21!!
A1
A2
A3
A4
A5
A6
A7
A8 1.25
A9
A10 14.50
A11
A12
A13
A14 0.25
A15
A16 15.00
A17 13.50
A18 0.50
A19
A20
A21 0.83
I am totally at a loss as to why it isn't finding and deleting cell A21 when the macro is run first.
Please help.
Owen