Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem with your <code>CountIF</code> call is that you're passing a poorly-formed string. You're literally passing "<code>range_FID &amp; ", " &amp; itm5</code>". </p> <p>First, you set to properly define range_fid:</p> <pre><code>Dim range_fid As Range Set range_fid = [A2:A7] </code></pre> <p>The call CountIF with:</p> <pre><code>count_fid_array(n) = Application.WorksheetFunction.CountIf(range_fid, itm5) </code></pre> <p>With that said, I would go about it differently:</p> <pre><code>Dim c As Range Dim people As Collection: Set people = New Collection Dim person As Collection Dim code As String For Each c In Range(Range("a2"), Range("a2").End(xlDown)) ' loop through all rows If IsNumeric(c.Offset(0, 1)) Then ' check if the ID is numeric or not code = "num" Else code = "alphanum" End If On Error Resume Next ' Needed in order to avoid error when person already exists in collection Set person = New Collection person.Add c.Value, "name" person.Add code, "code" people.Add person, c.Value ' will only be added if name doesn't already exist in collection On Error GoTo 0 If people(c.Value)("code") &lt;&gt; code Then ' if the format (alpha/num) of the ID on the current row is different than the format of a previous row for this name.... people(c.Value).Remove ("code") ' then set the code to "diff" people(c.Value).Add "diff", "Code" End If Next For Each person In people ' just display the content; you can take appropriate action here Debug.Print person("name") &amp; ": " &amp; person("code") Next </code></pre> <p>The result is a Collection containing names and a code for each. The code will be one of:</p> <ul> <li><strong>num</strong>: all values for a name are numeric (Bob)</li> <li><strong>alphanum</strong>: all values for a name are alphanumeric (Dan)</li> <li><strong>diff</strong>: name has at least one each of numeric and alphanumeric (Alice)</li> </ul> <p>Note that this could be done a little clearer with a Dictionary instead of a Collection, or with a Class, but I chose to take the most straightforward approach.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload