1

Ok, this has to be the easiest question ever, but I've been searching for awhile and can't figure this out. I have a very long list of values on sheet "Page1_1" (shtData) which I need to use to generate a list of unique values, along with a count of each unique value, on "Numbers". It's very simple to do manually by just copying to "Numbers" (shtNumbers) and removing duplicates, but the countif formula I use is very memory intensive, and bogs it all down. I have code to provide the unique list, but trying to get the count of each item is stumping me

Put simply: I need code to generate a list of unique values from "Page1_1" (shtData) A2:end of data, and put that list starting on "Numbers" (shtNumbers) A2 and down, then count occurrences and list the count in B2 and down.

current code:

shtData.Range("A2:A65536").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=shtNumbers.Range("A2"), Unique:=True

That code generates the list for me perfectly. I'd post what I've got for the count part, but it doesn't work at all, so I doubt it'd be helpful at all.

Thanks!

2
  • 2
    Why not use a Pivot Table? Commented Jan 4, 2018 at 21:45
  • I could, but I'd have to set it up every time I run this report, which is often. With a macro, I can just hit a command button and it's done. Of course, I also thought this would be easy to code, so what do I know? Commented Jan 4, 2018 at 21:46

2 Answers 2

2

Try this:

With shtNumbers

    With .Range(.Range("B2"),.Range("A2").End(xlDown).Offset(,1))

        .FormulaR1C1 = "=COUNTIF(Data!C[-1],RC[-1])" 'change data to actual sheet name

    End With

End With
Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly what I needed! Thanks for the quick reply.
1

Give this a try:

Sub SuperSimpleFrequencyTable()
    Dim C As Range, A As Range, B As Range

    Set A = Sheets("Page1_1").Range("A:A")
    Set B = Sheets("Numbers").Range("A:A")

    A.Copy B
    B.RemoveDuplicates Columns:=1, Header:=xlNo
    Set C = B.SpecialCells(xlCellTypeConstants).Offset(0, 1)

    With C
        .Formula = "=countif(Page1_1!A:A,A1)"
        .Value = .Value
    End With

End Sub

It will not leave formulas in the Numbers sheet.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.