macro to select table and remove duplicates problem.

0lzi

New Member
Joined
Sep 13, 2011
Messages
26
hi guys,

i recorded a macro that selects a sheet, highlights a table that is created from a MS query, then removes duplicates, then displays a msgbox to inform the user.

Code:
Sub Macro6()
'
' Macro6 Macro
'

'
    Sheets("Raw Data").Select
    ActiveSheet.Range("Table_Query_from_SFS[#All]").RemoveDuplicates Columns:= _
        Array(1, 2, 3, 4, 5, 6, 7, 8, 9), Header:=xlYes
        
        If xlYes Then MsgBox ("Duplicates Removed")
        
End Sub

the problem i have is i am calling this macro from another procedure, which works fine, but and the msgbox displays "Duplicates Removed" but it doesnt actually remove duplicates because i can manually goto the sheet after the procedure has finished and remove duplicates still, it the marco was working there would be no duplicates left and would get a msg saying that.

any help would be appreciated
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
the xlYes is used above in the Header:xlYes which when debugging is coming out true, so i used it in that 'if'

probably the wrong way to go about it but, the msgbox is essentialy just to check if the remove duplicates command actually worked, but it doesnt.
 
Upvote 0
i get that, thats why i used it for my 'IF' statement.

what im getting at was the duplicates should have been removed because Header:=xlYes
Code:
    ActiveSheet.Range("Table_Query_from_SFS[#All]").RemoveDuplicates Columns:= _
        Array(1, 2, 3, 4, 5, 6, 7, 8, 9), Header:=xlYes

the code shouldnt move on to the if statement untill this statement is done, but i cant get it to actually remove duplicates which is the problem. :)
 
Upvote 0
You won't see your message box until the RemoveDuplicates is done. But that doesn't mean that the RemoveDuplicates was successful. What happens with?

Code:
    Sheets("Raw Data").Range("Table_Query_from_SFS[#All]").RemoveDuplicates Columns:= _
        Array(1, 2, 3, 4, 5, 6, 7, 8, 9), Header:=xlYes

Generally there is no need to select an object before using its methods/properties. Do you have any error traps in your code?
 
Upvote 0
that code was done my recording a macro where i selected all the data in the table and removed duplicates, but when its called, the select sheet works but it doesnt appear to remove duplicates beause i can do it manually after the procedure has done and the msgbox shows up saying the duplicates have been removed.

and for this macro i havent put any error traps in, as i dont get any errors when it runs, it just doesnt do what its supposed to.
 
Upvote 0
plus im just coming up to the chapter in my vba book about error-handling, so hopefully il have some more info about how its done in vba
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

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