2016-09-13 6 views
0

VBAで式を追加しようとしていて、すべてのバリエーションを試しましたが、それでも動作しません。私はプロセスの一部として追加されたばかりのセルを追加しようとしています(オフセットを使用する必要があります)。VBAで式を追加する

allocatedtoSpend.Cells(Rows.count, 1).End(xlUp).Offset(-8, 4).Formula = "=IF('Expected Project Summary'!$I$20<0, """"Warning - you have exceeded the total budget"""",IF(VLOOKUP("" & allocatedtoSpend.Cells(Rows.count, 1).End(xlUp).Offset(-8, 0).Value & "",'Expected Project Summary'!$A$7:$I$16,7,FALSE)<0, """"Warning - you have exceeded the line budget"""", ""))" 

答えて

0

私はあなたの式の文字列があるべきだと思う:

"=IF('Expected Project Summary'!$I$20<0, ""Warning - you have exceeded the total budget"",IF(VLOOKUP(""" & allocatedtospend.Cells(Rows.Count, 1).End(xlUp).Offset(-8, 0).Value & """,'Expected Project Summary'!$A$7:$I$16,7,FALSE)<0, ""Warning - you have exceeded the line budget"", """"))" 

は、あなたのルックアップ値がテキストであると仮定します。それが数値の場合、あなたが必要となります

"=IF('Expected Project Summary'!$I$20<0, ""Warning - you have exceeded the total budget"",IF(VLOOKUP(" & allocatedtospend.Cells(Rows.Count, 1).End(xlUp).Offset(-8, 0).Value & ",'Expected Project Summary'!$A$7:$I$16,7,FALSE)<0, ""Warning - you have exceeded the line budget"", """"))" 

をそれは単にセルアドレスが含まれるように、おそらく簡単だ、それはどちらかのために動作します:

"=IF('Expected Project Summary'!$I$20<0, ""Warning - you have exceeded the total budget"",IF(VLOOKUP(" & allocatedtospend.Cells(Rows.Count, 1).End(xlUp).Offset(-8, 0).Address & ",'Expected Project Summary'!$A$7:$I$16,7,FALSE)<0, ""Warning - you have exceeded the line budget"", """"))" 
3

私は私を助けるために、「ヘルプ文字列を」使用それをデバッグして、私が得たコードは以下の通りです。

(私は"記号を取得するためにChr(34)を使用して好む)

Dim str As String 

str = "=IF('Expected Project Summary'!$I$20<0, " & Chr(34) & "Warning - you have exceeded the total budget" & Chr(34) & ",IF(VLOOKUP(" & allocatedtoSpend.Cells(Rows.Count, 1).End(xlUp).Offset(-8, 0).Value & ",'Expected Project Summary'!$A$7:$I$16,7,FALSE)<0, " & Chr(34) & "Warning - you have exceeded the line budget" & Chr(34) & "," & Chr(34) & Chr(34) & "))" 
Debug.Print str 

allocatedtoSpend.Cells(Rows.count, 1).End(xlUp).Offset(-8, 4).Formula = str 
関連する問題