vba code to copy unique data, transpose it and get count of the unique data

breilly00

Board Regular
Joined
Sep 15, 2008
Messages
53
Office Version
  1. 365
Platform
  1. Windows
I have a schedule of games for a sports league in sheet1 with dates in column “A” and remaining schedule data in the other columns. I need to take the dates and find just the unique dates and count the unique dates and paste them into a different sheet. The dates need to be transposed into column headers and the number of unique dates is needed to format the borders of where the dates were pasted. Also, the number of dates will change as new seasons are played.

I can copy the entire date column to a temporary sheet and use the range.remove duplicates to get the unique dates, get the number of unique dates by Cells count function and then using the range command by selecting the first cell and the count of unique dates to paste the dates in the new sheet with a transpose of true.

Is there a way that I can do this without the ‘gerry-rigging’ of using a temporary sheet. I need to take unique dates from a column of dates move them to rows in a new sheet and get the count to use when I format the columns.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
How about
Code:
Sub breilly00()
   Dim Cl As Range
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
         .Item(Cl.Value) = Empty
      Next Cl
      Sheets("Sheet6").Range("B1").Resize(, .Count).Value2 = .Keys
   End With
End Sub
 
Upvote 0
wow, that dictionary is something. However, my results are off.

My dates in column A are from 5/7/2019 repeating to 6/27/2019 with 5 rows for each of the individual dates (like below)
[TABLE="width: 72"]
<colgroup><col width="72" style="width:54pt"> </colgroup><tbody>[TR]
[TD="class: xl64, width: 72, align: right"]5/7/2019[/TD]
[/TR]
[TR]
[TD="class: xl64, align: right"]5/7/2019[/TD]
[/TR]
[TR]
[TD="class: xl64, align: right"]5/7/2019[/TD]
[/TR]
[TR]
[TD="class: xl64, align: right"]5/7/2019[/TD]
[/TR]
[TR]
[TD="class: xl64, align: right"]5/7/2019[/TD]
[/TR]
[TR]
[TD="class: xl64, align: right"]5/14/2019[/TD]
[/TR]
[TR]
[TD="class: xl64, align: right"]5/14/2019[/TD]
[/TR]
[TR]
[TD="class: xl64, align: right"]5/14/2019[/TD]
[/TR]
[TR]
[TD="class: xl64, align: right"]5/14/2019[/TD]
[/TR]
[TR]
[TD="class: xl64, align: right"]5/14/2019[/TD]
[/TR]
</tbody>[/TABLE]

the results that I get back are [TABLE="width: 792"]
<tbody>[TR]
[TD="class: xl65, width: 72, align: right"]5/7/19[/TD]
[TD="class: xl65, width: 72, align: right"]5/8/19[/TD]
[TD="class: xl65, width: 72, align: right"]5/9/19[/TD]
[TD="class: xl65, width: 72, align: right"]5/10/19[/TD]
[TD="class: xl65, width: 72, align: right"]5/11/19[/TD]
[TD="class: xl65, width: 72, align: right"]5/12/19[/TD]
[TD="class: xl65, width: 72, align: right"]5/13/19[/TD]
[TD="class: xl65, width: 72, align: right"]5/14/19[/TD]
[TD="class: xl65, width: 72, align: right"]5/15/19[/TD]
[TD="class: xl65, width: 72, align: right"]5/16/19[/TD]
[TD="class: xl65, width: 72, align: right"]5/17/19

[/TD]
[/TR]
</tbody>[/TABLE]

I need the results to be 5/7/19, 5/14/19, etc. until the last date. Tried changing the macro around that you gave me and things only got worse.
Will you provide me with direction that I need to take?

In the mean time, I am going to look at that 'scripting dictionary' object to learn what it is doing. Seems like a great tool.
 
Upvote 0
With data like


Excel 2013/2016
A
207/05/2019
307/05/2019
407/05/2019
507/05/2019
607/05/2019
714/05/2019
814/05/2019
914/05/2019
1014/05/2019
1114/05/2019
1221/05/2019
1321/05/2019
1421/05/2019
1521/05/2019
1621/05/2019
1728/05/2019
1828/05/2019
1928/05/2019
2028/05/2019
2128/05/2019
Dates


I get


Excel 2013/2016
ABCDE
107/05/201914/05/201921/05/201928/05/2019
Sheet6


Check that those other dates don't appear in column A
 
Upvote 0
Sticking my tail between my legs.

Now I run it again, 3 times, and the correct dates show up. Problem must have been "PIBCAKB" ------- Problem Is Between Chair And Key Board

Fluff, UR the greatest. My hat is off to you for the quick and ACCURATE response to my 'newbee' question.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,956
Messages
6,175,616
Members
452,661
Latest member
Nonhle

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top