2013-07-31 41 views
0

所以我沒有太多的編程經驗,而且幾乎沒有VBA的經驗。我的主要問題是,我的代碼中的公式延伸超過1行,並且當我包含下劃線,空格然後開始新行時,我收到錯誤。如何通過1行代碼擴展VBA中的公式

我重視的代碼的PIC,有可能是不必要的代碼行,因爲我錄一個宏獲取代碼。什麼我試圖做

的更多信息:

我有使用「數據有效性」包含在細胞和基於從該列表中選擇,下面將輸出池的特定列表的列表。

這些列表的信息存儲在工作簿中的其他工作表上。

我能夠在「數據驗證」列表源框中爲多個輸入工作開發IF語句。不過,我有84種可能性,並且我無法適應列表源代碼框中的所有單個if語句。因此,我決定嘗試使用VBA通過錄制多個輸入「數據驗證」if語句的宏來手動輸入公式。

下面是代碼:

Sub HelpSetUp() 
    With Selection.Validation 
     .Delete 
     .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ 
     xlBetween, Formula1:= _ 
     "=if($B$2='fuel columns'!$A$1,agriculturalbiproduct,if($B$2='fuel  columns'!$B$1,agriculturalresidue,if($B$2='fuel columns'!$C$1,agriculturalwaste,Nofuel)))" 
     .IgnoreBlank = True 
     .InCellDropdown = True 
     .InputTitle = "" 
     .ErrorTitle = "" 
     .InputMessage = "" 
     .ErrorMessage = "" 
     .ShowInput = True 
     .ShowError = True 
    End With 
End Sub 

回答

3

當你有文本的長位擠進來,您需要使用「&」,並把它分解成塊_。

像這樣

暗淡ASTRING作爲字符串

aString = "four score and seven years ago our fathers " & _ 
    "set forth on this continent a new nation, " & _ 
    "conceived in liberty and dedicated to the " & _ 
    "proposition that all men are created equal." 

一定要離開&和之間的空間_。

SMW

+0

如果您接受我的回答,請點擊大號下方的複選標記。這將是我第一個接受的答案! –