How can I edit this macro to run on active column?

HockeyDiablo

Board Regular
Joined
Apr 1, 2016
Messages
182
I have columns up to ("PL") and I would like to remove duplicates from each column.

Sub Macro3()


' Macro3 Macro


Selection.EntireColumn.SelectColumns("AA:AA").Select
ActiveSheet.Range("$AA$1:$AA$96769").RemoveDuplicates Columns:=1, Header:= _
xlNo
Selection.EntireColumn.Hidden = True "hides the column so I know what one I ran the duplicate check on"
End Sub
Selection.EntireColumn.Select

Can I change the range to run this or is there a way to run a quick macro to click on the column to selct all and then run the macro for the selected column??
 
Last edited:

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Sub Macro4()
'
' Macro4 Macro
'


'
ActiveCell.EntireColumn.RemoveDuplicates Columns:=1, Header:=xlNo
ActiveCell.EntireColumn.Hidden = True

End Sub


works when you click on the whole column.

need a loop on the columns now, any help?
 
Upvote 0
Have a look on this


Code:
Sub Macro4()

'If you want to start with column A
Range("A1").Select
'comment the line above to start with the currently selected cell

For counter = 1 To 10  'amount of columns[INDENT]ActiveCell.EntireColumn.Select[/INDENT]
[INDENT]ActiveCell.EntireColumn.RemoveDuplicates Columns:=1, Header:=xlNo
activecell.offset(0,1).select[/INDENT]
[INDENT]ActiveCell.EntireColumn.Offset(0, -1).Hidden = True[/INDENT]
Next


End Sub


Hope it helps
 
Last edited by a moderator:
Upvote 0
Have a look on this


Code:
Sub Macro4()

'If you want to start with column A
Range("A1").Select
'comment the line above to start with the currently selected cell

For counter = 1 To 10  'amount of columns[INDENT]ActiveCell.EntireColumn.Select[/INDENT]
[INDENT]ActiveCell.EntireColumn.RemoveDuplicates Columns:=1, Header:=xlNo
activecell.offset(0,1).select[/INDENT]
[INDENT]ActiveCell.EntireColumn.Offset(0, -1).Hidden = True[/INDENT]
Next


End Sub


Hope it helps


Simply brilliant, thank you for the lesson.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
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