When this code was originally established, the requirements provided to me were to identify instances where the data in columns A, B, C, D & G matched; and place a Y in a particular column. If the data across the same columns did not match, create a new record. Now, the requirements have changed. I now need to code for some instances using columns A, B, C, D & G; some instances using only column A, and some instances using only column B; based on the Queue.
I'm not even entirely certain where to start. Should I look at creating multiple dictionaries based on the Queue? I'm thinking that there has to be a simpler way.
Here is the code that I'm using now:
I'm not even entirely certain where to start. Should I look at creating multiple dictionaries based on the Queue? I'm thinking that there has to be a simpler way.
Here is the code that I'm using now:
Code:
Private Sub MD1_TP_Bump()
Application.ScreenUpdating = False
Dim m As Workbook
Dim mTP, mMD1 As Worksheet
Dim mMDLR, mTPLR As Long
Dim Rng As Range
Dim RngList As Object
Set m = ThisWorkbook
Set mTP = ThisWorkbook.Sheets("Total_Population")
Set mMD1 = ThisWorkbook.Sheets("MD1")
Set RngList = CreateObject("Scripting.Dictionary")
mMDLR = mMD1.Range("A" & Rows.Count).End(xlUp).Row
mTPLR = mTP.Range("A" & Rows.Count).End(xlUp).Row
'Adds data from columns A, B, C, D & G; from the Total Population tab; to the dictionary.
For Each Rng In mTP.Range("A2", mTP.Range("A" & mTP.Rows.Count).End(xlUp))
If Not RngList.Exists(Rng.Value & "|" & Rng.Offset(0, 1) & "|" & Rng.Offset(0, 2) & "|" & Rng.Offset(0, 3) & "|" & Rng.Offset(0, 6)) Then
RngList.Add Rng.Value & "|" & Rng.Offset(0, 1) & "|" & Rng.Offset(0, 2) & "|" & Rng.Offset(0, 3) & "|" & Rng.Offset(0, 6), Rng
Else
Set RngList(Rng.Value & "|" & Rng.Offset(0, 1) & "|" & Rng.Offset(0, 2) & "|" & Rng.Offset(0, 3) & "|" & Rng.Offset(0, 6)) = _
Union(RngList(Rng.Value & "|" & Rng.Offset(0, 1) & "|" & Rng.Offset(0, 2) & "|" & Rng.Offset(0, 3) & "|" & Rng.Offset(0, 6)), Rng)
End If
Next
'If the data in columns A, B, C, D & G on the MD1 tab have a match on the Total Population tab, insert Y in the MD1 column. If there isn't a match _
the entire record is copied from MD1 and pasted to TP.
For Each Rng In mMD1.Range("A2", mMD1.Range("A" & mMD1.Rows.Count).End(xlUp))
If RngList.Exists(Rng.Value & "|" & Rng.Offset(0, 1) & "|" & Rng.Offset(0, 2) & "|" & Rng.Offset(0, 3) & "|" & Rng.Offset(0, 6)) Then
RngList(Rng.Value & "|" & Rng.Offset(0, 1) & "|" & Rng.Offset(0, 2) & "|" & Rng.Offset(0, 3) & "|" & Rng.Offset(0, 6)).Offset(, 12).Value = "Y"
ElseIf Not RngList.Exists(Rng.Value & "|" & Rng.Offset(0, 1) & "|" & Rng.Offset(0, 2) & "|" & Rng.Offset(0, 3) & "|" & Rng.Offset(0, 6)) Then
mMD1.Range("A" & Rng.Row & ":P" & Rng.Row).Copy mTP.Cells(mTP.Rows.Count, "A").End(xlUp).Offset(1, 0)
End If
Next
RngList.RemoveAll
Call Formatting
Application.ScreenUpdating = True
End Sub