VBA Excel Replace not always working

OK, that really bothers me.

In the end, I want to add some if and else to this code, but for now I just have the code below.

' resize string if nessuary  
sname = Replace(arr(x), "ASR Port Provisioning General Questions", "General Questions")  
sname = Replace(arr(x), "ASR Port Provisioning", "ASR PP")  
sname = Replace(arr(x), "ASR Standard Network Device Config Changes", "Std Config Change")  
If Len(sname) > 30 Then sname = Right(sname, 15)  

arr () has elements

"ASR Port Provisioning General Questions", 
"ASR Port Provisioning",
"ASR Standard Network Device Config Changes"

Now for "ASR Network Adapter Configuration Change" it works and is shortened to "STD Config Change"

But for the other two, are they skipped and not replaced?

Now I know that they contain information about the root, I even tried to output arr (x) to form a seach string, but this still will not happen :)

OK it seems that it needs to be cleaned after it has been damaged by if and elses

If InStr (arr (x), "ASR Port") Then

    If InStr(arr(x), "ASR Port Provisioning General Questions") Then
    sname = "General Questions"
    Else
    sname = Replace(arr(x), "ASR Port Provisioning", "ASR PP")
    End If

    Else
    sname = Replace(arr(x), "ASR Standard Network Device Config Changes", "Std Config Change")
End If

Work great! any one whey three replace ogather statutes stop each other?

+3
1

, sname , , "sticks". , , . , .

ASR Port arr(x) , , Else.

, - :

If InStr(arr(x), "ASR Port Provisioning General Questions") Then
    sname = Replace(arr(x), "ASR Port Provisioning General Questions", "General Questions")  

ElseIf InStr(arr(x), "ASR Port Provisioning") Then
    sname = Replace(arr(x), "ASR Port Provisioning", "ASR PP")  

Else
    sname = Replace(arr(x), "ASR Standard Network Device Config Changes", "Std Config Change") 

End If
+1

All Articles