View Single Post
 
Old 06-12-2014, 06:57 AM
BobBridges's Avatar
BobBridges BobBridges is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default

Interesting. I never knew about the Application.InputBox method, so I've learned something new. And I don't know why you'd want to do this with a macro instead of just putting the COUNTIF function in the sheet itself. (But clearly you realize you could do that, so I assume you have a reason for wanting to do it this way.)

It isn't clear to me why this would be slow to run. The hard-coded COUNTIF range is fewer than 100 cells, so it should be pretty fast. How many cells are typically in Range2? I would think anything under 250 would be no problem.

All that aside, I can see a more complicated but much quicker way to write this. The way you set it up, Excel has to COUNTIF all 87 cells in Range1 for every cell in Range2. The quicker way to do it is to COUNTIF all the values in Range1 once, table the results and then check the table while processing Range2. In fact, you don't even need the count, do you? You just want to know whether a given value appears at all in Range1.

I started to show sample code that would do this, but realized that I was assuming that all the values you're checking on are text, not numeric. How you do this depends on whether the values you're checking for are all text, all numeric or may be either. Tell me about that, please.
Reply With Quote