Copy unique data and count total


Please help create a macro which is able to copy only unique title from Column D (Data sheet) to Total sheet (Column A). However, at Total sheet need to count how many time and at what date (Column A, Data sheet) the data are appeared in Data sheet. This value need to be captured at Total sheet according to date (B2:AF2).  I have manually copied few data at Total sheet for Experts to get a better view. Hope Experts could help me create this macro.



Count1.xls
Billa7Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rory ArchibaldCommented:
Try this - note you will need to unmerge cells A1 and A2 on the Total sheet first:

Sub MakeSummaryTable()
   Dim lngLastRowData As Long
   Dim lngLastRowTotals As Long
   
   ' clear existing data
   Sheets("Total").UsedRange.Offset(2).ClearContents
   
   ' Get unique list
   With Sheets("Data")
      ' get last used row in col D (Titles)
      lngLastRowData = .Cells(.Rows.Count, "D").End(xlUp).Row
      .Range("D1:D" & lngLastRowData).AdvancedFilter Action:=xlFilterCopy, _
        CopyToRange:=Sheets("Total").Range("A2"), Unique:=True
   End With
   
   With Sheets("Total")
      ' get last used row in col A (Titles)
      lngLastRowTotals = .Cells(.Rows.Count, "A").End(xlUp).Row
      ' sort Titles
      .Range("A2", .Cells(lngLastRowTotals, "A")).Sort Key1:=.Range("A2"), Order1:=xlAscending, Header:=xlYes, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortTextAsNumbers
      
       .Range("B3:AF" & lngLastRowTotals).FormulaR1C1 = _
        "=SUMPRODUCT((DAY(Data!R2C1:R" & lngLastRowData & "C1)=R2C)*(Data!R2C4:R" & lngLastRowData & "C4=RC1))"
   End With
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Billa7Author Commented:
Hi Rorya,

Thanks for the code. Is that any possible when I run this code with different set of data at Data sheet,
keep the the old data at Total sheet, but update the new eatery at column A and at the same time continues counting counting the total availability of the data at column (B2:AF2 - Total sheet).  
0
Rory ArchibaldCommented:
Not sure what you mean - do you mean that you would be entering just a new month's data but still want to keep the previous totals (and add to them where applicable) on the Total sheet? If so, that will require a completely different approach.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Billa7Author Commented:
Hi Rorya,

You're right. Hope you will consider this.
0
Rory ArchibaldCommented:
Yes - bit busy at the moment though. If no-one jumps in beforehand, I will try and take a look in the next few days.
0
Billa7Author Commented:
Hi Rorya,

I found a workaround process to achieve the result without having a new macro. Your suggested code just doing the job. Is that way for us not displaying the formula at the cell? the end result only display the value when we click at the cell.
0
Rory ArchibaldCommented:
Do you mean you want the formulas replaced with static values, or that you don't want anything to appear in the cell unless you click on it?

If the former, then change lines 24 and 25 to:

With .Range("B3:AF" & lngLastRowTotals)
   .FormulaR1C1 = _
        "=SUMPRODUCT((DAY(Data!R2C1:R" & lngLastRowData & "C1)=R2C)*(Data!R2C4:R" & lngLastRowData & "C4=RC1))"
   .Value = .Value
End With

Open in new window

0
Billa7Author Commented:
Excellent!!
Thanks a lot Rorya.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.