Excel 2013 - insert if condition met

Soldato
Joined
6 Mar 2008
Posts
10,085
Location
Stoke area
Hi all,

I have a csv file with 2300 entries in it that are lists of addresses.

However, like most addresses they vary in the amount of information they have.

I need to select a column, for instance, column E, then if it has "England" in the cell I need to insert a blank cell and shift them right.

Anyone know how to do this in bulk instead of manually?
 
I think VBA is the only way to automate this. The following should work, you just need to alter for the ranges you want, and what value to check for.

Code:
Sub shiftRightIf()
    
    For Each cell In Range("E1:E10").Cells
    
        If cell.Value = "England" Then
            cell.Select
            Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
        End If
    Next
    
End Sub

With your CSV file open, in Excel goto visual basic editor, add a module and then paste this code. You should then just be able to run it like a macro.
 
Hi,

Just to clarify....

You have a column for each line of the address, and if this is the case the "Engalnd" is always moving?

Ignore... ^^

Regards
 
Last edited:
Back
Top Bottom