Hi,
The attached code does what you want but I don't have a good feeling about it. I feel that an easier solution should have been possible without the use of code, either with a pivot table or an array formula. If there is some one out there who knows how to do it, please do step into the ring.
Meanwhile, your names can get sorted using oldfashioned VB code. All of it is in one module which may be called by any name you like. I have left the default name of Module1.
To install it, Open the VB Editor window, either by pressing Alt+F11 or by selecting Tools / Macro / Visual Basic Editor from your CommandBar.
You should see the Project Explorer window on the left of the VBE window. It lists the open workbooks’ work and code sheets. If you don’t see it, open it by selecting View / Project Explorer or by pressing Ctrl+R.
To insert the code module right-click on the name of your VB Project (that is, the name of your workbook). In the dropdown that opens, select Insert / Module. It will be called Module1 by default if there aren’t any other modules with default names already.
Paste the code into this module.
You can call the code from the Tools menu. Press Tools / Macro / Macros.
From the list that opens select “CountNames” and press the Run button.
Except within the attached workbook, don't do that before you have set the constants you see at the top of the code module and copied below here:
- Code: Select all
Const DataSheet As String = "Names"
Const FirstDataRow As Long = 2
Const FirstDataCol As String = "A"
Const LastDataCol As String = "I"
Const ResultSheet As String = "Occurrences"
Const FirstResultRow As Long = 2
Const FirstResultCol As String = "A"
The worksheets "Names" and "Occurrences" must exist. If you want to use other names, make sure that the names on their tabs and in the Constants are identical. First and last columns and first rows must be entered in the constants. The last rows will be found by the macro.
If you have questions, please ask. If not, happy counting!
You do not have the required permissions to view the files attached to this post.
Have a great day!
Sisyphus
I do this for "honour and country" - much less of the latter, actually.
If I helped you, award points, plenty of them.
If I bored you, deduct points for being too long-winded. (I know, :lol)