Macro Help - delete columns, remove duplicates, formatting

max8719

Board Regular
Joined
Jan 9, 2015
Messages
71
Hi All,

:confused:Im struggling with this, any ideas will be much appreciated.


I have a table A1 to M500.
I need to
switch columns L and M values
Then
delebte columns B, C and I
Then
replace duplicate values with blanks apart from the first instance in columns A then B then C.
Then
resize all columns to fit word legnth and apply all boarders to the table with a font of 16 through out.

Thanks in advance
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
This is constructed based on the original post, but excludes the Border formatting which I will leave to you.
Code:
Sub doStuff()
Dim sh As Worksheet
Set sh = ActiveSheet
    With sh
        .Columns("N").Insert
        .Columns("L").Cut .Range("N1")
        .Columns("L").Delete
        Union(Columns("B:C"), Columns("I")).Delete
        For i = 1 To 3
            For j = .Cells(Rows.Count, i).End(xlUp).Row To 2 Step -1
                If Application.CountIf(.Range(.Cells(1, i), .Cells(j, i)), Cells(j, i).Value) > 1 Then
                    .Cells(j, i).ClearContents
                End If
            Next
        Next
        .Columns("A:M").AutoFit
    End With
End Sub
I noted that by deleting only the cell in columns A, B and C which are duplicates or other cells, it will leave any data in columns, D:M intact for those rows. I assume you had considered that in your planning.
 
Upvote 0
This is constructed based on the original post, but excludes the Border formatting which I will leave to you.
Code:
Sub doStuff()
Dim sh As Worksheet
Set sh = ActiveSheet
    With sh
        .Columns("N").Insert
        .Columns("L").Cut .Range("N1")
        .Columns("L").Delete
        Union(Columns("B:C"), Columns("I")).Delete
        For i = 1 To 3
            For j = .Cells(Rows.Count, i).End(xlUp).Row To 2 Step -1
                If Application.CountIf(.Range(.Cells(1, i), .Cells(j, i)), Cells(j, i).Value) > 1 Then
                    .Cells(j, i).ClearContents
                End If
            Next
        Next
        .Columns("A:M").AutoFit
    End With
End Sub
I noted that by deleting only the cell in columns A, B and C which are duplicates or other cells, it will leave any data in columns, D:M intact for those rows. I assume you had considered that in your planning.

Hi,

Would it be possible for the rows stay in the same order?
 
Upvote 0
Hi,

Would it be possible for the rows stay in the same order?

They should be in the same order. The macro works from the bottom up. The only change should be that duplicates in columns A:C will be blank cells. If you mean columns, the only ones that change are the two you wanted swapped.
 
Last edited:
Upvote 0
Adding to post # 4. Three columns were deleted entirely in addition to using an insert and delete to swap coloumns L and M. If your table has formulas which are dependent on any of the columns which were deleted or cells that were cleared of data, then the results may give the appearance of rows having been changed. But there was not any action that would change the original order of the rows. If you could post a screen shot of your sheet or a link and maybe give a more comprehensive description of your objective, perhaps I could give you a better solution.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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