vba to clear cell contents if it's left aligned

MeganDHarris

New Member
Joined
Sep 6, 2018
Messages
2
I need assistance developing a macro that will clear cell contents based on it's text alignment. I have a column in my excel sheet that contains both project names aligned to the right and subtask names aligned to the left. I need the column to be separated into 2 columns - one with just the project names and and with just the subtask names. Is there some simple vba code that will copy the column then delete all the left aligned text out of the first column and all the right aligned text out of the second column? Any help will be greatly appreciated - thank you!!!
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
This code assumes your data is in Column A and the left aligned will be placed in column B

Code:
Sub leftalign()
    Dim lr As Long, i As Long
    lr = Range("A" & Rows.Count).End(xlUp).Row
    For i = 1 To lr
        If Range("A" & i).HorizontalAlignment <> -4152 Then
            Range("A" & i).Cut Range("A" & i).Offset(0, 1)
        End If
    Next i


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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