Why can you not test compare(i)=compare(j) [[or compare(i,1)=compare(j,1) as 2D arrays]]? This is not the kind of VBA programming I do, so I'm not very good at it, but I have never heard that you cannot test two variants for "exactly equal to". I have heard of other issues with testing for "exactly equal to" (round off error and such), but not that variants cannot inherently be so tested. It would appear to me that, with the recognition that compare is actually a 2D array, it should be fairly straightforward to test for compare(j,1)=compare(i,1).

Using variants can be one trick to speed some of these things up sometimes. In some ways, though, the hard reality of what you are doing (as I understand it so far) is that your current algorithm is asking the computer (whether using VBA or using the COUNTIF() worksheet function) to perform 90 trillion (300000*300000) operations, and that is just to test compare(i)=compare(j). That does not include incrementing loop counters, retrieving data from the spreadsheet or putting data in the spreadsheet and so on.

I suspect that, if VBA is really going to be useful for speeding this operation up, you will need a better algorithm -- not some "trick" based on variable data type. For example: could you sort the input data? If the input data were sorted, you would not need to test every entry. You would only need to count the number "A"s in a localized block until you come to an "AB" entry, then you can count the AB entries.

As I noted, this is not the kind of programming I do, so there are certainly others here may be better at developing this type of algorithm. I think you will need to research some other ideas to really see any gains in computation time.