Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop and check dublicates

Status
Not open for further replies.

Xsi

Programmer
May 29, 2015
121
SE
Hello people,

I have got a excel sheet that contain 5 columns (A,B,C,D,E)

I need a code to loop first column "E" and for each used cell in column "E" check in all used cells column "a" if the content is the same if then clear" then loops b,c and D.

Could someone help me?

Thank you in advance.
 
Ho,

Your requirement is not clear.

Please post an example of your table along with the expected result.

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
sorry I have already solved it :)


Code:
Sub CompareLists()
Dim Rng As Range, RngList As Object

Set RngList = CreateObject("Scripting.Dictionary")


For Each Rng In Range("A1", Range("A" & Rows.Count).End(xlUp))
  If Not RngList.Exists(Rng.Value) Then
    RngList.Add Rng.Value, Nothing
  End If
Next

For Each Rng In Range("E1", Range("E" & Rows.Count).End(xlUp))
  If RngList.Exists(Rng.Value) Then
    Rng.Clear
  End If
Next

End Sub
 
Or, even better:

Code:
Private sub CompareList(rCol as String)
	Dim Rng As Range 
	Dim RngList As Object

	Set RngList = CreateObject("Scripting.Dictionary")

	For Each Rng In Range(rCol, Range(Left(RCol,1) & Rows.Count).End(xlUp))
  		If Not RngList.Exists(Rng.Value) Then
    			RngList.Add Rng.Value, Nothing
  		End If
	Next
End sub

Now call it twice (or a thousand times):

Code:
ComapareList("A1")
ComapareList("E1")
...
CompareList(......

ATB,

Darrylle

Never argue with an idiot, he'll bring you down to his level - then beat you with experience.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top