Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm trying to write a program that will take a column of strings and return
the string that occurs most in the list. Any suggestions? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Brad,
It won't surprise me if someone comes up with a method of doing this with formulas directly on the worksheet. However, as you asked for code, here is an example. Sub FrequencyOfStr() Dim rngColumn As Range Dim strSave As String Dim lngCount As Long Dim lngSave As Long Dim c As Range 'Edit "Sheet1" in following line to your sheet With Sheets("Sheet1") 'Edit "E" in thefollowing code to your column Id Set rngColumn = Range(.Cells(1, "E"), _ .Cells(.Rows.Count, "E").End(xlUp)) End With For Each c In rngColumn lngCount = WorksheetFunction. _ CountIf(rngColumn, c.Value) If lngCount lngSave Then lngSave = lngCount strSave = c.Value End If Next c MsgBox "Most frequent string = " & strSave & Chr(13) & _ "Number of occurrences = " & lngSave End Sub -- Regards, OssieMac "Brad" wrote: I'm trying to write a program that will take a column of strings and return the string that occurs most in the list. Any suggestions? |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Perhaps like this
=INDEX(E1:E100,MODE(IF(E1:E100<"",MATCH(E1:E100,E 1:E100,0)))) This is an array formula which must be entered by pressing CTRL+Shift+Enter 'and not just Enter. If you do it correctly then Excel will put curly brackets 'around the formula {}. You can't type these yourself. If you edit the formula 'you must enter it again with CTRL+Shift+Enter. Mike "OssieMac" wrote: Hi Brad, It won't surprise me if someone comes up with a method of doing this with formulas directly on the worksheet. However, as you asked for code, here is an example. Sub FrequencyOfStr() Dim rngColumn As Range Dim strSave As String Dim lngCount As Long Dim lngSave As Long Dim c As Range 'Edit "Sheet1" in following line to your sheet With Sheets("Sheet1") 'Edit "E" in thefollowing code to your column Id Set rngColumn = Range(.Cells(1, "E"), _ .Cells(.Rows.Count, "E").End(xlUp)) End With For Each c In rngColumn lngCount = WorksheetFunction. _ CountIf(rngColumn, c.Value) If lngCount lngSave Then lngSave = lngCount strSave = c.Value End If Next c MsgBox "Most frequent string = " & strSave & Chr(13) & _ "Number of occurrences = " & lngSave End Sub -- Regards, OssieMac "Brad" wrote: I'm trying to write a program that will take a column of strings and return the string that occurs most in the list. Any suggestions? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Counting the frequency of a text string | Excel Discussion (Misc queries) | |||
Frequency of a word string in an excel database | Excel Discussion (Misc queries) | |||
Importing Long String - String Manipulation (INVRPT) (EDI EANCOM 96a) | Excel Programming | |||
histograms - frequency and relative frequency? | Excel Discussion (Misc queries) | |||
frequency of characters within a string | Excel Programming |