So I have developed an algorithm that breaks down a word into multiple parts based on certain rules about letter occurrences within the word. I have managed to debug the entire algorithm and now for the sake of convenience for the user, I am trying to put it into a Worksheet_Change method like this:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim arr() As String
Dim i As Byte
Dim j As Byte
If (Target.Column = 1) Then
If (Target.Value <> "") Then
arr() = BreakupWord("perform")
For i = 1 To 10
Cells(Target.Row, i + 1) = arr(i)
Next i
ElseIf (Target.Value = "") Then
For j = 1 To 10
Cells(Target.Row, i + 1) = ""
Next j
End If
End If
End Sub
Basically, the variable arr() stores the broken down components of the word "Target" in its array and via a For loop I try to print out the contents into cells on the worksheet considering the user has made a change only in column A of the worksheet as given by the conditions
Now, the problem is such: I tested multiple words one line after the other and the code runs smoothly. However, if I go to an already entered word in column A and delete it via Backspace or Delete, my code seems to enter an infinite loop and Excel crashes. What is possibly the problem and how can I avoid it?