2013-07-31 72 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

如果您接受我的回答,请点击大号下方的复选标记。这将是我第一个接受的答案! –