Asuming that all your strings are in one column, you can add a second column with their position (line number) and do a pivot table across the strings displaying the counts.
In order to get the position(s) of a string you are interested in, you use the pivot table's drill-down function (double click on the count next to a string) which will create a new sheet with all detail records - and the position will be displayed
Hope that helps
Good lock
EDIT after comments exchanged:
I would go for a solution that scans your data only 1 time and not recursively, copying values to a second sheet:
for each string in sourcetable
if found in targettable
increase targettable.counter by 1 (remark: in column_2)
else
put sourcetable.string at end of targettable
put "1" in targettable.counter (remark: occurence = 1 in column_2)
endif
put sourcetable.index into targettable.column(counter+2)
next
so far the metacode .... do you need more help to actually code this in VBA?
EDIT 2
OK .... made a quick & dirty one ....
Sub CountString()
Dim S As Range, T As Range, Idx As Long, Jdx As Long
Set S = Worksheets("Sheet1").[A2] ' first row is header
Set T = Worksheets("Sheet2").[A2] ' first row is header
Idx = 1
Do While S(Idx, 1) <> ""
Jdx = FindInRange(T, S(Idx, 1))
If T(Jdx, 1) = "" Then
T(Jdx, 1) = S(Idx, 1)
T(Jdx, 2) = 1
T(Jdx, 3) = Idx
Else
T(Jdx, 2) = T(Jdx, 2) + 1
T(Jdx, T(Jdx, 2) + 2) = Idx
End If
Idx = Idx + 1
Loop
End Sub
Function FindInRange(R As Range, A As String) As Long
Dim Idx As Long
Idx = 1
Do While R(Idx, 1) <> ""
If R(Idx, 1) = A Then
Exit Do
End If
Idx = Idx + 1
Loop
FindInRange = Idx
End Function
tested with 500 words from "Lorem ipsum" - takes below 1 second, output in sheet_2 looks like
String Count Position ...
Lorem 1 1
ipsum 6 2 45 65 232 323 462
dolor 5 3 42 214 321 335
sit 6 4 79 148 249 295 415
amet 6 5 80 149 250 296 416
consectetur 8 6 117 288 298 396 457 473 486
adipiscing 3 7 180 402
Hope that helps