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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
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,226,739
Messages
6,192,739
Members
453,755
Latest member
IQBS

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