johnmerlino
Board Regular
- Joined
- Sep 21, 2010
- Messages
- 94
Hey all,
I would like to convert this:
abc SR abc &
abc JR abc TR
to this:
abc abc
abc abc
In this code:
for the substring array, it only ever applies the last index. It's as if the indexes before the last get overwritten or something. For example, if JR is last index, then it will only remove JR from string. If SR is last index, then it will only remove SR from string.
Thanks for response.
I would like to convert this:
abc SR abc &
abc JR abc TR
to this:
abc abc
abc abc
In this code:
Code:
Sub StringChecker()
Dim string_arr() As Variant
Dim k As Integer
Dim c As Range
Set c = ActiveSheet.[A1]
end_string = Array(" &", _
" TR", _
" SR", _
" DEFEN")
substring = Array(" SR ", _
" JR ")
Do While c <> "End Loop"
c.Offset(0, 1) = c
For k = 0 To UBound(end_string)
If Right(c, Len(end_string(k))) = end_string(k) Then
cleaner_string = Mid(c, 1, Len(c) - Len(end_string(k)))
End If
Next k
For l = 0 To UBound(substring)
clean_string = Replace(cleaner_string, substring(l), " ")
Next l
c.Offset(0, 1) = clean_string
Set c = c.Offset(1, 0)
Loop
End Sub
for the substring array, it only ever applies the last index. It's as if the indexes before the last get overwritten or something. For example, if JR is last index, then it will only remove JR from string. If SR is last index, then it will only remove SR from string.
Thanks for response.