Remove blank cells in a given range (remove gaps between cells)

thedeadzeds

Active Member
Joined
Aug 16, 2011
Messages
451
Office Version
  1. 365
Platform
  1. Windows
Guys, is there a way to via vba move all of the names so there are no gaps so example 1 looks like example 2. The data is currerntly in range c22 to E40 in sheet called 'Allocate'

EXAMPLE 1
[TABLE="class: grid, width: 456"]
<colgroup><col span="2"><col></colgroup><tbody>[TR]
[TD]Name1[/TD]
[TD]Name2[/TD]
[TD]Name3[/TD]
[/TR]
[TR]
[TD]Angela Rose[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]Bethan Mason[/TD]
[TD] [/TD]
[TD]Angela Rose[/TD]
[/TR]
[TR]
[TD]Chloe Whitfield[/TD]
[TD]Bethan Mason[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD]Angela Rose[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]Chloe Whitfield[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD]Angela Rose[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]Lorna Young[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]Bethan Mason[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]Nicole Foxwell[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
</tbody>[/TABLE]

EXAMPLE 2
[TABLE="class: grid, width: 456"]
<colgroup><col span="2"><col></colgroup><tbody>[TR]
[TD]Name1[/TD]
[TD]Name2[/TD]
[TD]Name3[/TD]
[/TR]
[TR]
[TD]Angela Rose[/TD]
[TD]Bethan Mason[/TD]
[TD]Angela Rose[/TD]
[/TR]
[TR]
[TD]Bethan Mason[/TD]
[TD]Chloe Whitfield[/TD]
[TD]Angela Rose[/TD]
[/TR]
[TR]
[TD]Chloe Whitfield[/TD]
[TD]Bethan Mason[/TD]
[TD]Angela Rose[/TD]
[/TR]
[TR]
[TD]Lorna Young[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Nicole Foxwell[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Try:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG16Nov56
[COLOR="Navy"]Dim[/COLOR] rng [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Set[/COLOR] rng = Range("A:c").SpecialCells(xlCellTypeBlanks)
rng.Delete shift:=xlUp
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
try
Code:
Sub removeblanks()
Range("C22:E40").SpecialCells(xlBlanks).Delete xlShiftUp
End Sub
 
Last edited:
Upvote 0
You can also:- Select area.
Then "Home" > "Find & Select" > "Go to special" > "Blank"> "Ok.
Right click Area, "Select Delete" > "shift Cells Up" > "OK"
 
Upvote 0

Forum statistics

Threads
1,223,250
Messages
6,171,036
Members
452,374
Latest member
keccles

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