View Full Version : [SOLVED:] Target - Specific Arrays - Within Arrays
Good Friday all,
Now i have my multidimensional array set up, but i have a snag somewhere
I can't work out - 1 detail
if i want to replace array terms in - Array 0
with array terms in Array 1 - what do i need to do?
eg
1,2, 3 becomes A, B,C
Sub Array_Test()
Dim j As Long
Dim k As Long
oProduct = Array(Array(1, 2, 3), Array(A, B, c), Array(4, 5, 6))
k = 2
For j = LBound(oProduct) To UBound(oProduct)
Set oRng = ActiveDocument.Range
With oRng.Find
Do While .Execute(oProduct(j)(0), MatchWholeWord:=True)
oRng.Text = oProduct(k)(j)
oRng.Collapse 0
Loop
End With
Next j
End Sub
Something about my k's and j's in the loop
gmaxey
12-08-2017, 05:16 AM
Sub Array_Test()
'A basic Word macro modified by Greg Maxey, http://gregmaxey.com/word_tips.html, 12/8/2017
'*** Questions\Comments
'1. Why do you dim some variables but not others?
Dim oRng As Range
'2. If j and k are confusing, why do you use them?
'Dim j As Long
'Dim k As Long
Dim lngIndex As Long
Dim oProduct 'dimmed as variant
'3. As ArraySortMethods(4,5,6) appears to have no bearing on the desired result, why is it there?
'4. The following statement, in addition to the apparently superfluous Array(4,5,6) contains variant
'variables A, B and C (with no value). Even if your code worked the replacement values would be
'nothing, nothing and nothing.
'oProduct = Array(Array(1, 2, 3), Array(A, B, C), Array(4, 5, 6))
'5. Here A, B and C are replaced with literal string values A B and C
oProduct = Array(Array(1, 2, 3), Array("A", "B", "C"))
'k = 1
For lngIndex = LBound(oProduct) To UBound(oProduct(0))
Set oRng = ActiveDocument.Range
With oRng.Find
' Do While .Execute(oProduct(0)(lngIndex), MatchWholeWord:=True)
' oRng.Text = oProduct(1)(lngIndex)
' oRng.Collapse 0
' Loop
'Or
.Execute FindText:=oProduct(0)(lngIndex), MatchWholeWord:=True, ReplaceWith:=oProduct(1)(lngIndex), Replace:=wdReplaceAll
End With
Next lngIndex
lbl_Exit:
Exit Sub
End Sub
Hello Greg,
nice to see you this friday!
Well now i give my usual list of excuses, of course some are ridiculously unvalid!
well I started off with an array in excel, then i made a multidimensional 1
So then I transferred it over to word, and somewhere in the haze the array wires got crossed.
Now yes i pardone me but i forgot to copy over my variables there was a variant some where.
But needs less to be said , i was confused about my
dim i
and then i made a dim k to add in...
any way its all making as much sense as a dogs dinner.
Now my Array works nicely because i can add them into 1 master array and then, use 1 at a time
Well thank you very much for the write up, i do appreciate the short sharp clean code compared to mine
and happy friday
folks and all
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.