Quick VBA help required please

SV18

Board Regular
Joined
Sep 1, 2008
Messages
157
Hello all,

I'm working on some address data, currently the addresses have blanks in some of the cells which end up splitting the address details.

I've written the following to remove the blanks, it isn't however working as sometimes there is more than one blank. So it doesn't line up as it should

For Each C in Range("b2:f6")
If C.value = "" then
C.Delete shift:=xlToLeft​
End If
Next C

Has anyone got any ideas of how I can do this?
EEID
Address1
Address2
Address3
Address4
Address5
8002
1 Road
Street
Town
Town
8003
2 Road
Street
Town
Town
8004
3 Road
Street
Town

<TBODY>
</TBODY>
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
Sub test()
Dim i As Long, j As Long
For i = 2 To 6
    For j = 6 To 2 Step -1
        If Cells(i, j).Value = "" Then Cells(i, j).Delete shift:=xlShiftToLeft
    Next j
Next i
End Sub
 
Upvote 0

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
59,294
Office Version
  1. 365
Platform
  1. Windows
You could also consider doing all the blanks directly and at once rather than looping through all the cells individually to check.
Code:
Sub Delete_Blanks()
  On Error Resume Next
  Range("A1").CurrentRegion.SpecialCells(xlBlanks).Delete Shift:=xlToLeft
  On Error GoTo 0
End Sub
 
Upvote 0

Forum statistics

Threads
1,191,117
Messages
5,984,747
Members
439,907
Latest member
Kayfabe

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
Top