Very Good,
Let's see how is the code:
Problems:Code:Private Sub CommandButton1_Click() On Error GoTo studyerror Dim i, j As Integer 'counters Dim var As String 'takes the text Dim size As Integer 'takes the number of words in the text Dim matrix As Variant Dim mtx() As String ActiveWorkbook.Sheets("frequency").Select Cells.Delete var = TextBox1.Text matrix = Split(var, " ") 'separates each word of text in an array index. 'MsgBox matrix(3), for example size = UBound(matrix) 'takes the number of words in the text ReDim mtx(2, size) As String 'resizes the array to fit all the words; THE ERROR IS HERE, why? For i = 0 To size 'from 1 to size mtx(0, i) = matrix(i) 'the first receives the word mtx(1, i) = 1 'the second receives zero Next 'The number of appearances of the word stored in mtx (i, 0) is stored in mtx (i, 1) For i = 0 To size For j = 0 To size If i <> j Then 'not to equate one thing with itself If mtx(0, i) = mtx(0, j) Then 'when it finds the same word. mtx(1, i) = mtx(1, i) + 1 'the counter receives one more. End If End If Next Next 'This saves the words on the worksheet. Range("A1").Select For i = 0 To size ActiveCell.Offset(i, 0) = mtx(1, i) ActiveCell.Offset(i, 1) = mtx(0, i) Next 'Now, we sort according to column B and excluded the repeated words. Call Macro1 Range("B2").Select For i = 0 To size If ActiveCell.Text = ActiveCell.Offset(-1, 0).Text Then ActiveCell.EntireRow.Delete End If ActiveCell.Offset(1, 0).Select Next Exit Sub studyerror: MsgBox "Error number: " And Err.Number End Sub Sub Macro1() ' ' Macro1 Macro ActiveWorkbook.Worksheets("frequency").Sort.SortFields.Clear ActiveWorkbook.Worksheets("frequency").Sort.SortFields.Add Key:=Range("B1"), _ SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal With ActiveWorkbook.Worksheets("frequency").Sort .SetRange Range("B:B") .Header = xlNo .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With End Sub
1. Does not differentiate between words that contain point, comma, etc.. (important)
2. By listing the words, unable to delete repeated items.
3. Do not jump in line "textbox!
But it seems it's working. Thanks.




Reply With Quote
