B
bojan0810
Hi all
Sub Rectangle1_Click()
CopyUniques Sheets("sheet1").Range("a2:a1000"), Sheets("Pick List").Range("a2")
End Sub
Sub CopyUniques(rngCopyFrom As Range, rngCopyTo As Range)
Dim d As Object, c As Range, k
Set d = CreateObject("scripting.dictionary")
For Each c In rngCopyFrom
If Len(c.Value) > 0 Then
If Not d.Exists(c.Value) Then d.Add c.Value, 1
End If
Next c
k = d.keys
rngCopyTo.Resize(UBound(k) + 1, 1).Value = Application.Transpose(k)
End Sub
I have this macro in button, but that isnt problem.
So it copies unique value from one sheet to another. Works great, but it has one problem.
If I delete one value in sheet 1, it doesnt remove that value in Pick List sheet.
For example
a
a
b
c
c
And when macro do his it will be like this
a
b
c
But If I remove for example last c in first sheet it stays
a
b
c
c
I want to make something like overwrite macro or something like that, so it doesnt leave like that
Thank you
Sub Rectangle1_Click()
CopyUniques Sheets("sheet1").Range("a2:a1000"), Sheets("Pick List").Range("a2")
End Sub
Sub CopyUniques(rngCopyFrom As Range, rngCopyTo As Range)
Dim d As Object, c As Range, k
Set d = CreateObject("scripting.dictionary")
For Each c In rngCopyFrom
If Len(c.Value) > 0 Then
If Not d.Exists(c.Value) Then d.Add c.Value, 1
End If
Next c
k = d.keys
rngCopyTo.Resize(UBound(k) + 1, 1).Value = Application.Transpose(k)
End Sub
I have this macro in button, but that isnt problem.
So it copies unique value from one sheet to another. Works great, but it has one problem.
If I delete one value in sheet 1, it doesnt remove that value in Pick List sheet.
For example
a
a
b
c
c
And when macro do his it will be like this
a
b
c
But If I remove for example last c in first sheet it stays
a
b
c
c
I want to make something like overwrite macro or something like that, so it doesnt leave like that
Thank you