Hello, I created a frequency count of words given by the following code:However, an error occurred while trying to resize array, why? What I make to it works?Code:Private Sub CommandButton1_Click() 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(1, 1) As String var = TextBox1.Text matrix = Split(var, " ") 'separates each word of text in an array index. size = UBound(matrix) 'takes the number of words in the text ReDim mtx(size, 2) 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(i, 0) = matrix(i) 'the first receives the word mtx(i, 1) = 0 '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(i, 0) = mtx(j, 0) Then 'when it finds the same word. mtx(i, 1) = mtx(i, 1) + 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(i, 0) ActiveCell.Offset(i, 1) = mtx(i, 1) Next 'Now, we sort according to column B and excluded the repeated words. End Sub
Thank you.




Reply With Quote
