The purpose of this program is to remove letters from cells. For some reason when it the replace function line executes it gets stuck in an infinite loop. If the cell contains 456po83 once the variables are incremented until they both equal p it the letter in the cell should be replaced with nothing and o is now the 4th character in the string and the variables should keep incrementing right? What am I missing here?
Option Explicit
Sub DeleteB()
Dim stringLength As Integer
Static str As String
Dim A As Integer
Dim num As Integer
Dim indvChar As String
Dim B As Integer
Dim charArray(0 To 25) As String
charArray(0) = "a"
charArray(1) = "b"
charArray(2) = "c"
charArray(3) = "d"
charArray(4) = "e"
charArray(5) = "f"
charArray(6) = "g"
charArray(7) = "h"
charArray(8) = "i"
charArray(9) = "j"
charArray(10) = "k"
charArray(11) = "l"
charArray(12) = "m"
charArray(13) = "n"
charArray(14) = "o"
charArray(15) = "p"
charArray(16) = "q"
charArray(17) = "r"
charArray(18) = "s"
charArray(19) = "t"
charArray(20) = "u"
charArray(21) = "v"
charArray(22) = "w"
charArray(23) = "x"
charArray(24) = "y"
charArray(25) = "z"
Do Until IsEmpty(Selection)
A = 1
num = Len(Selection)
str = Selection.Value
Do Until A = num + 1
indvChar = Mid(str, A, 1)
B = 0
Do Until B = 26
If indvChar = charArray(B) Then
Selection.Value = Replace(str, indvChar, "", 1)
Else: B = B + 1
End If
Loop
A = A + 1
Loop
ActiveCell.Offset(1, 0).Select
Loop
End Sub
strdoes not change and there for every loop you are replacingstrminus the letter being replaced, but sincestritself is not saving the change the letter replaced still exists when you move to the next character instr.