Loop through empty cells and data move to one cell left

AT BABU

Board Regular
Joined
Oct 12, 2018
Messages
54
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

Loop through empty cells and data move to one cell left
[TABLE="width: 456"]
<tbody>[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD][/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD][/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD][/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD][/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]



[TABLE="width: 392"]
<tbody>[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]11/6/2019[/TD]
[TD]Normal[/TD]
[TD]28035[/TD]
[TD]Y[/TD]
[TD]NO[/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try this

Code:
Sub Macro1()
  Range("B1:B" & Range("A" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeBlanks).Delete Shift:=xlToLeft
End Sub
 
Upvote 0
Code:
Sub Macro1()
  Range("B1:B" & Range("A" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeBlanks).Delete Shift:=xlToLeft
End Sub
You can probably simplify your line of code safely to this...
Code:
[B:B].SpecialCells(xlBlanks).Delete Shift:=xlToLeft
as the SpecialCells function automatically limits its actions to the worksheet's UsedRange. (I said "safely" because under certain circumstances, the UsedRange can be larger than the displayed values, but that is unusual and deleting blanks from blank rows will not produce any errors.) Also note that I used xlBlanks instead of xlCellTypeBlanks... You can omit the CellType portion of the predefined constant arguments for the SpecialCells function and they will still work.
 
Last edited:
Upvote 0
Thanks Rick
85521263791736bfd534ca63896ea875.jpg
for the comments.
 
Upvote 0

Forum statistics

Threads
1,223,764
Messages
6,174,364
Members
452,558
Latest member
jswan83

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