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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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
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,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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