Remove Duplicate Cells in a Row

后端 未结 4 2090
醉酒成梦
醉酒成梦 2021-01-16 09:04

Just to clarify : I don\'t want to remove duplicates rows, I want to remove Duplicate Cells within a row

So here\'s a classic address table, and in some row there\'s

4条回答
  •  醉酒成梦
    2021-01-16 09:51

    Probably the easiest would be with a dictionary. Read the current cell. If it is already in the dictionary then blank out the cell, otherwise add it to the dictionary.

    Dim dict As New Scripting.Dictionary 
    For counterRow = 1 To LastRow         
       key = // get the current cell value
       If Not dict.Exists(key) Then 
           dict.Add key, "1"
       Else
          // clear current cell
    End If Next counterRow 
    

    More on dictionary here: Does VBA have Dictionary Structure?

    PS: Note that my solution removes all duplicates, not just if they are in the 2nd and 3rd column as in your example.

提交回复
热议问题