Dear Great Minds of Excel,
I have a code I found on this site that creates a unique list and would like to modify it to create a unique list, in numerical code order, if the values fall between two dates.
Codes are listed in Column C. Dates are listed in Column D. The date range will be on a userform but I reference them on the "Report" worksheet in Cell "A1" and "A2". I have several worksheets that the code will act upon and store the final list in one column on the worksheet "Report". My worksheets are all called PCODE1, PCODE2, PCODE3, PCODE4, PCODE5, PCODE6, PCODE7, PCODE7, PCODE8, and PCODE9. I do not need the date column, just included it as a reference to the activity that occurred during the date range. Column B and Column C is the expected results of the code.
Here are example sheets of the start and finished results.
START
(this sheet name is "PCODE1")
[TABLE="width: 500"]
<tbody>[TR]
[TD]Column B
[/TD]
[TD]Column C
[/TD]
[TD]Column D
[/TD]
[/TR]
[TR]
[TD]Activity Survey
[/TD]
[TD]Code
[/TD]
[TD]Date
[/TD]
[/TR]
[TR]
[TD]Survey
[/TD]
[TD]1001
[/TD]
[TD]2/1/13
[/TD]
[/TR]
[TR]
[TD]Control
[/TD]
[TD]1002
[/TD]
[TD]2/9/13
[/TD]
[/TR]
[TR]
[TD]Control
[/TD]
[TD]1002
[/TD]
[TD]3/5/13
[/TD]
[/TR]
[TR]
[TD]Inspection
[/TD]
[TD]1008
[/TD]
[TD]2/22/13
[/TD]
[/TR]
[TR]
[TD]Survey
[/TD]
[TD]1001
[/TD]
[TD]3/8/13
[/TD]
[/TR]
[TR]
[TD]Survey
[/TD]
[TD]1001
[/TD]
[TD]2/1/13
[/TD]
[/TR]
[TR]
[TD]Treatment
[/TD]
[TD]1003
[/TD]
[TD]2/15/13
[/TD]
[/TR]
</tbody>[/TABLE]
(this sheet name is "PCODE2")
[TABLE="width: 500"]
<tbody>[TR]
[TD]Column B
[/TD]
[TD]Column C
[/TD]
[TD]Column D
[/TD]
[/TR]
[TR]
[TD]Activity Control
[/TD]
[TD]Code
[/TD]
[TD]Date
[/TD]
[/TR]
[TR]
[TD]Document 1 Issued
[/TD]
[TD]2001
[/TD]
[TD]2/7/13
[/TD]
[/TR]
[TR]
[TD]Document 2 Issued
[/TD]
[TD]2002
[/TD]
[TD]3/9/13
[/TD]
[/TR]
[TR]
[TD]Document 2 Issued
[/TD]
[TD]2002
[/TD]
[TD]2/5/13
[/TD]
[/TR]
[TR]
[TD]Quality Check
[/TD]
[TD]2008
[/TD]
[TD]2/22/13
[/TD]
[/TR]
[TR]
[TD]Quality Check
[/TD]
[TD]2008
[/TD]
[TD]3/8/13
[/TD]
[/TR]
[TR]
[TD]Quality Check
[/TD]
[TD]2008
[/TD]
[TD]1/1/13
[/TD]
[/TR]
[TR]
[TD]Control Monitoring
[/TD]
[TD]2010
[/TD]
[TD]2/15/13
[/TD]
[/TR]
</tbody>[/TABLE]
END - The results will be on sheet "Report" between Dates 2/1/13 to 2/28/13 located in Cells "A1" and "A2" respectively. I only need to have Columns B and C. I do not need the date column.
Desired Result
(this sheet name is "PCODE2")
[TABLE="width: 500"]
<tbody>[TR]
[TD]Column A
[/TD]
[TD]Column B
[/TD]
[/TR]
[TR]
[TD]Activity Control
[/TD]
[TD]Code
[/TD]
[/TR]
[TR]
[TD]Survey
[/TD]
[TD]1001
[/TD]
[/TR]
[TR]
[TD]Control
[/TD]
[TD]1002
[/TD]
[/TR]
[TR]
[TD]Treatment
[/TD]
[TD]1003
[/TD]
[/TR]
[TR]
[TD]Inspection
[/TD]
[TD]1008
[/TD]
[/TR]
[TR]
[TD]Document 1 Issued
[/TD]
[TD]2001
[/TD]
[/TR]
[TR]
[TD]Document 2 Issued
[/TD]
[TD]2002
[/TD]
[/TR]
[TR]
[TD]Quality Check
[/TD]
[TD]2008
[/TD]
[/TR]
[TR]
[TD]Control Monitoring
[/TD]
[TD]2010
[/TD]
[/TR]
</tbody>[/TABLE]
What I have so far is the following:
The code lists all the unique code values from worksheet(PCODE1) and lists on worksheet (Report) but I need to modify to include the activity heading and descriptions in Column B that corresponds to Column C then the ability to check all other PCODE sheets and list as described. I hope this post was clear. any help is greatly appreciated. Thank you in advance.
Craig
I have a code I found on this site that creates a unique list and would like to modify it to create a unique list, in numerical code order, if the values fall between two dates.
Codes are listed in Column C. Dates are listed in Column D. The date range will be on a userform but I reference them on the "Report" worksheet in Cell "A1" and "A2". I have several worksheets that the code will act upon and store the final list in one column on the worksheet "Report". My worksheets are all called PCODE1, PCODE2, PCODE3, PCODE4, PCODE5, PCODE6, PCODE7, PCODE7, PCODE8, and PCODE9. I do not need the date column, just included it as a reference to the activity that occurred during the date range. Column B and Column C is the expected results of the code.
Here are example sheets of the start and finished results.
START
(this sheet name is "PCODE1")
[TABLE="width: 500"]
<tbody>[TR]
[TD]Column B
[/TD]
[TD]Column C
[/TD]
[TD]Column D
[/TD]
[/TR]
[TR]
[TD]Activity Survey
[/TD]
[TD]Code
[/TD]
[TD]Date
[/TD]
[/TR]
[TR]
[TD]Survey
[/TD]
[TD]1001
[/TD]
[TD]2/1/13
[/TD]
[/TR]
[TR]
[TD]Control
[/TD]
[TD]1002
[/TD]
[TD]2/9/13
[/TD]
[/TR]
[TR]
[TD]Control
[/TD]
[TD]1002
[/TD]
[TD]3/5/13
[/TD]
[/TR]
[TR]
[TD]Inspection
[/TD]
[TD]1008
[/TD]
[TD]2/22/13
[/TD]
[/TR]
[TR]
[TD]Survey
[/TD]
[TD]1001
[/TD]
[TD]3/8/13
[/TD]
[/TR]
[TR]
[TD]Survey
[/TD]
[TD]1001
[/TD]
[TD]2/1/13
[/TD]
[/TR]
[TR]
[TD]Treatment
[/TD]
[TD]1003
[/TD]
[TD]2/15/13
[/TD]
[/TR]
</tbody>[/TABLE]
(this sheet name is "PCODE2")
[TABLE="width: 500"]
<tbody>[TR]
[TD]Column B
[/TD]
[TD]Column C
[/TD]
[TD]Column D
[/TD]
[/TR]
[TR]
[TD]Activity Control
[/TD]
[TD]Code
[/TD]
[TD]Date
[/TD]
[/TR]
[TR]
[TD]Document 1 Issued
[/TD]
[TD]2001
[/TD]
[TD]2/7/13
[/TD]
[/TR]
[TR]
[TD]Document 2 Issued
[/TD]
[TD]2002
[/TD]
[TD]3/9/13
[/TD]
[/TR]
[TR]
[TD]Document 2 Issued
[/TD]
[TD]2002
[/TD]
[TD]2/5/13
[/TD]
[/TR]
[TR]
[TD]Quality Check
[/TD]
[TD]2008
[/TD]
[TD]2/22/13
[/TD]
[/TR]
[TR]
[TD]Quality Check
[/TD]
[TD]2008
[/TD]
[TD]3/8/13
[/TD]
[/TR]
[TR]
[TD]Quality Check
[/TD]
[TD]2008
[/TD]
[TD]1/1/13
[/TD]
[/TR]
[TR]
[TD]Control Monitoring
[/TD]
[TD]2010
[/TD]
[TD]2/15/13
[/TD]
[/TR]
</tbody>[/TABLE]
END - The results will be on sheet "Report" between Dates 2/1/13 to 2/28/13 located in Cells "A1" and "A2" respectively. I only need to have Columns B and C. I do not need the date column.
Desired Result
(this sheet name is "PCODE2")
[TABLE="width: 500"]
<tbody>[TR]
[TD]Column A
[/TD]
[TD]Column B
[/TD]
[/TR]
[TR]
[TD]Activity Control
[/TD]
[TD]Code
[/TD]
[/TR]
[TR]
[TD]Survey
[/TD]
[TD]1001
[/TD]
[/TR]
[TR]
[TD]Control
[/TD]
[TD]1002
[/TD]
[/TR]
[TR]
[TD]Treatment
[/TD]
[TD]1003
[/TD]
[/TR]
[TR]
[TD]Inspection
[/TD]
[TD]1008
[/TD]
[/TR]
[TR]
[TD]Document 1 Issued
[/TD]
[TD]2001
[/TD]
[/TR]
[TR]
[TD]Document 2 Issued
[/TD]
[TD]2002
[/TD]
[/TR]
[TR]
[TD]Quality Check
[/TD]
[TD]2008
[/TD]
[/TR]
[TR]
[TD]Control Monitoring
[/TD]
[TD]2010
[/TD]
[/TR]
</tbody>[/TABLE]
What I have so far is the following:
Code:
Sub UniqueList3()
Dim vArr As Variant
Dim Dict As Object
Dim i As Long
Dim j As Long
Dim n As Integer
Dim lnglastpc As Long
Dim lnglastpd As Long
'Clear old data
Range("A4:O1000").Select
Selection.ClearContents
Range("A4").Select
'Create Heading
Range("A4") = Sheets("PCODE1").Range("B8")
Range("B4") = Sheets("PCODEs").Range("C8")
'Find first available row on "Report" worksheet to list codes and description
n = Range("B" & Rows.count).End(xlUp).Row + 1
vArr = Sheets("PCODE1").Range("C9:C1000").Value2
' initialise dictionary
Set Dict = CreateObject("scripting.dictionary")
With Dict
' case-insensitive comparison
.CompareMode = vbTextCompare
' store distinct values from column A as keys
' (ignoring blank cells)
For i = 1 To UBound(vArr, 1)
For j = 1 To UBound(vArr, 2)
If Len(vArr(i, j)) > 0 Then
If Not .Exists(vArr(i, j)) Then _
.Add Key:=vArr(i, j), Item:=0
End If
Next j
Next i
' print output array
Range("B" & n).Resize(.count, 1) = _
Application.Transpose(.Keys)
End With
Craig