I suspect COUNTIF is not providing the correct answers because you have a mixture of numbers and numbers stored as text.
You should be able to work around this by forcing a formatted count. As an excel formula, this would look something like:
=COUNTIF($A$2:$A$349397,TEXT($A12,"#"))
One way to do this in VBA is something like:
Sub AltCountIf()
Dim x, y
Dim i As Long
With Application
.ScreenUpdating = False: .DisplayAlerts = False: .EnableEvents = False
End With
With Sheet1.Cells(1).CurrentRegion
'assume column A contains the data values to be counted
x = .Columns(1).Value
'assume column B will hold the results
y = .Columns(2).Value 'don't really need values, will just initialise y
'skip the header row and loop through to do the countifs
For i = 2 To UBound(x, 1)
y(i, 1) = Application.CountIf(.Columns(1), Format(x(i, 1), "#"))
Next
'write the results back to column B
.Columns(2).Value = y
End With
With Application
.ScreenUpdating = True: .DisplayAlerts = True: .EnableEvents = True
End With
MsgBox "Completed"
End Sub
Display More
This loads the entire dataset to be counted into an array and then places the countif values into a second array.
It may be more efficient than other types of loops however with nearly 350,000 rows this is still going to be very slow.
Also, loading all the data into arrays first may be more efficient but it will be memory intensive.
If you want to test it first maybe try using a smaller loop eg: