PDA

View Full Version : delete blank cells in every row individually



lasher18
04-10-2021, 07:51 AM
Hi all,
I have been trying to automate the following task with the macro recorder. I did it for one row, now I need to do that for every row individually through a range iteration. Let's say my range is A2:J23.
Could you help me?
Thanks


Sub Macro1()'
' Macro1 Macro
'


'
Range("D756").Select
Range(Selection, Selection.End(xlToRight)).Select
Range("D756:U756").Select
Selection.Delete Shift:=xlToLeft
Range("D756").Select
Range(Selection, Selection.End(xlToRight)).Select
Range("D756:AH756").Select
Selection.Delete Shift:=xlToLeft


End Sub

SamT
04-10-2021, 08:15 AM
Start at bottom, work right to left, then up. Test on a Copy first

Sub MessedUp()
Dim i as long
Application.ScreenUpdating = False
With Range("A2:J23")
For i = .Count to 1 Step -1
If .Cells(i) = "" Then .cells(i).Delete Shift:=xlToLeft
Next i
End With
Application.ScreenUpdating = True
End Sub

p45cal
04-10-2021, 10:53 AM
Select the range you want to delete blanks from and run this:

Sub blah()
Selection.SpecialCells(xlCellTypeBlanks).Delete Shift:=xlToLeft
End Sub
If you know the range you want to delete blanks from then the likes of:

Sub blah()
Range("A2:J23").SpecialCells(xlCellTypeBlanks).Delete Shift:=xlToLeft
End Sub