Macro to move range of cells if certain cell is not blank

lmasala

New Member
Joined
Jul 25, 2011
Messages
11
I have a list of addresses. Most follow the format Street Address in Column A, City in Column B, County in C, State in D. But some have an Apartment Number in Column B that pushes the rest of the address back so that State ends up in Column F.

What I am trying to do: Insert blank Column B. If the cell in Column F is not blank then move cells in Columns C-F to Columns B-E, otherwise do nothing. After looping through all rows, delete Column F.

I know this is pretty simple but my brain is fried today and I am getting nowhere. Thanks in advance for any help. I really, really appreciate it!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
For anyone that is trying to do something similar, this is what I ended up with. I realize it's ugly, but I'm new at this and it seems to get the job done. Any advice on making it less awful is more than welcome. Thanks!

Code:
    Columns("B").Select
    Selection.Insert

    Dim unitRange As Range
    Dim cell As Range
    Set unitRange = Range("F1")
    Set unitRange = Range("F1:F300") 
    For Each cell In unitRange
     If cell <> "" Then
         cell.Activate
         Selection.Offset(0, -3).Resize(Selection.Rows.Count + 0, _
         Selection.Columns.Count + 3).Copy
         ActiveCell.Offset(0, -4).Activate
         ActiveCell.PasteSpecial
      End If
    Next cell

    Columns("F").Select
    Selection.Delete
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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