-
Skipping Array Terms
Good day folks,
I wanted to understand some logic about array terms
It’s a bit back wards but I wanted to see how to do this
Now if the Replace term = "SKIP" completely skip the search term and its execution
Code:
Sub Skip_Array_Terms()
Dim oRng As Word.Range
Dim arrWords As Variant
Dim oReplace As Variant
Dim i As Long, j As Long
arrWords = Array("A", "B", "C", "D")
oReplace = Array("Apple", "SKIP", "Cat", "SKIP")
For i = 0 To UBound(arrWords)
Set oRng = ActiveDocument.Range
j = 0
With oRng.Find
Do While .Execute(FindText:=arrWords(i), MatchWholeWord:=True)
'IF oReplace(i)="SKIP" << something like this?
oRng = oReplace(i)
oRng.Collapse 0
Loop
End With
Next i
Set oRng = Nothing
End Sub
What are the ways I may be able to achieve something like this, if it’s the same word then it is easier a clause somehwere?
I dont know if i would need to split the array as its the same word on the replace i would like to skip
-
I think what you are looking for is
Code:
Sub Skip_Array_Terms()
Dim oRng As Word.Range
Dim arrWords As Variant
Dim oReplace As Variant
Dim i As Long
arrWords = Array("A", "B", "C", "D")
oReplace = Array("Apple", "SKIP", "Cat", "SKIP")
For i = 0 To UBound(arrWords)
If Not UCase(oReplace(i)) = "SKIP" Then
Set oRng = ActiveDocument.Range
With oRng.Find
Do While .Execute(FindText:=arrWords(i), MatchWholeWord:=True)
oRng = oReplace(i)
oRng.Collapse 0
Loop
End With
End If
Next i
Set oRng = Nothing
End Sub
Note that access to the Arrays is case sensitive.
-
Hello Graham,
Nice to see you.
Oh yes this is the exact simple line that makes it easy for me to understand.
Code:
If Not UCase(oReplace(i)) = "SKIP" Then
Normally you skip terms on the search, but I didn’t want to split my arrays every time I had to skip a replacement, so it had to be backwards.
Now let me play about with this, because I do have a feeling seeing how useful it is
I may make an array of terms in the replacement to skip. eg
Code:
oSkipTerms = Array("SKIP1", "SKIP2")
If Not UCase(oReplace(i)) = oSkipTerms(j) Then
So it will be array within array
I'll pop back later with my new update
Good Sunday Graham