2017-02-16 18 views
0

次のコードブロックを参考にしてください。私がここでやろうとしているのは、文字に含まれる静的変数を対応する値に置き換えることです。Excel VBA置換する文字列と置換する配列の値を置換する

コードはテーブルをループし、[変数]列の各行はその変数のインスタンスを 'blankLetter'のインスタンスに置き換えます。

letterReplace = Replace(blankLetter, "<PURVNAME>", letterArray("<PURVNAME>")) 

しかし、この行が何も置き換えません:

letterReplace = Replace(blankLetter, temp, letterArray(temp)) 

アイブ氏が持っていたが多分これは次が正常に動作します

Public Function letterReplace(blankLetter As String, letterArray As Dictionary) As String 
'Lookup the variable table and for each variable replace the instance of that in the array 
Application.ScreenUpdating = False 
Dim row As Range 
Dim temp As String 
For Each row In [varTable[Variable]].Rows 
    'temp = "<PURVNAME>" 
    temp = row.Value 
    letterReplace = Replace(blankLetter, temp, letterArray(temp)) 
Next 
Application.ScreenUpdating = True 
End Function 

...これを達成するための最良の方法ではありません検索が終わりました。

助けがあれば助かります。

マーク

+0

データの例を表示することをお勧めします。 – user3598756

答えて

0

ループを通るたびに、単一のは、元のblankLetter引数に置き換えるとletterReplaceに結果を置き実行します。これらの唯一の最後の操作は、戻り値としての機能のうち、それを作るだろう交換してください。

同じ変数に対してReplace操作を実行し続ける必要があります。

Public Function letterReplace(blankLetter As String, letterArray As Dictionary) As String 
'Lookup the variable table and for each variable replace the 
' instance of that in the array 

    Dim row As Range, retVal As String 
    Dim temp As String 

    retVal = blankLetter 
    For Each row In [varTable[Variable]].Rows 
     temp = row.Value 
     retVal = Replace(retVal, temp, letterArray(temp)) 
    Next 

    letterReplace = retVal 
End Function 
+0

ティム・ウィリアムズのお手伝いをありがとうございました。乾杯。 –