Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Macro for deleting empty cells 1

Status
Not open for further replies.

pbcharlie

Technical User
Jan 16, 2002
55
does anyone have a macro that will delete all empty cells within a range and move the rest to the right or left?
Thanks in advance
Charlie
 
Charlie,

I have a piece of code where I filter and delete based on a number of criteria. Here are the relevant lines:

Code:
w.Columns.AutoFilter Field:=2, Criteria1:=vntWebIDFltrs(i)
w.Rows("2:" & Selection.End(xlDown).Row).Delete shift:=xlUp

where w is dimmed as a worksheet and vntWebIDFltrs(i) is an array of of criteria I have defined for filtering. You can modify it to something like this:

Code:
w.Columns.AutoFilter Field:=2, Criteria1:=Empty
w.("B2:B" & Selection.End(xlDown).Row).Delete shift:=xlToLeft

You may need to play with it a little in order to get it to work in your sub.

HTH MM
 
I managed to write this.
Sub delete_empty_cells()
'
'
' © 21/02/2003 by Charlie Snedden
'
'
'


Dim looper
Dim looperx
For looperx = 1 To 210
For looper = 1 To 200
ActiveCell.Offset(0, 1).Select




Do While IsEmpty(ActiveCell)


ActiveCell.Delete Shift:=xlToLeft
ActiveCell.Offset(0, -1).Select
Do While IsEmpty(ActiveCell)

ActiveCell.Offset(0, -1).Select
Loop
Loop
Next looper
Selection.End(xlToLeft).Select
ActiveCell.Offset(-1, 0).Select
Next looperx
End Sub


Thanks for you help.

Charlie Thanks in advance
Charlie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top