ExcelMentee
Banned - Rules violations
- Joined
- Jan 11, 2021
- Messages
- 31
- Office Version
- 365
- Platform
- Windows
I have been using below code to Filter the Unique values from Sheet1 and paste them into Sheet2 my code is working fine. But it has one issue that is when i remove any value from Sheet1.Range(C4:C) cell it gives empty cell in Sheet2 like in below image.
I want that if i remove any cell value from Sheet1 range then Code should automatically adjust it. there should not be any empty cell in Sheet2 Range.
I also wants to add sort function in the code so unique values will be popup with sorting A to Z in sheet2.
I tried at my end to do both things but cannot do. Your help in this regard will be highly appreciated.
I want that if i remove any cell value from Sheet1 range then Code should automatically adjust it. there should not be any empty cell in Sheet2 Range.
I also wants to add sort function in the code so unique values will be popup with sorting A to Z in sheet2.
I tried at my end to do both things but cannot do. Your help in this regard will be highly appreciated.
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim d As Object, c As Variant, i As Long, lr As Long
Set d = CreateObject("Scripting.Dictionary")
lr = Cells(Rows.Count, 1).End(xlUp).Row
c = Sheet1.Range("C4:C" & lr)
For i = 1 To UBound(c, 1)
d(c(i, 1)) = 1
Next i
Sheet2.Range("C4").Resize(d.Count) = Application.Transpose(d.keys)
End Sub