Problem to solve for:
Sheet1 in my workbook refreshes daily. Column B in Sheet1 populates several rows with Account Names (and account names can have multiple rows).
I want Sheet2 Column A in my workbook to populate a distinct list of distinct accounts from Column B in Sheet1, WITH THE CATCH being, I want this to continuously append as Sheet1 will populate a new list of Accounts daily. In other words, if there are 5 accounts today, and 2 accounts tomorrow, I want Sheet 2 Column A to show all 7 Accounts.
I've scraped together some code from other posts that I thought would do this, but it's not populating anything in Sheet2. Please see the attached image and code below:
Code:
Sub TestMacro()
Dim Cell As Range
Dim Key As String
Dim Dict As Object
Dim LookupWks As Worksheet
Dim MstrWks As Worksheet
Dim NextCell As Range
Dim r As Long
Set MstrWks = ThisWorkbook.Worksheets("Sheet1")
Set LookupWks = ThisWorkbook.Worksheets("Sheet2")
Set Dict = CreateObject("Scripting.Dictionary")
Dict.CompareMode = vbTextCompare
For r = 2 To MstrWks.Cells(Rows.Count, "A").End(xlUp).Row
Key = MstrWks.Cells(r, "A")
If Trim(Key) <> "" Then
If Not Dict.Exists(Key) Then
Dict.Add Key, r
End If
End If
Next r
Set NextCell = LookupWks.Cells(2, "A").End(xlUp).Offset(1, 0)
For r = 2 To LookupWks.Cells(Rows.Count, "A").End(xlUp).Row
Key = LookupWks.Cells(r, "A")
If Trim(Key) <> "" Then
If Not Dict.Exists(Key) Then
NextCell.Value = Key
Set NextCell = NextCell.Offset(1, 0)
End If
End If
Next r
End Sub
I've done quite a bit of research on this topic, and hacked together some code from other posts and tweaks that I had seen, but it's not populating anything.