为变量分配多行值

时间:2011-06-14 12:54:21

标签: vba excel-vba excel

我想将多行的值分配给 VBA 示例中的变量:

Dim campaign_date As Variant
campaign_date = "ABC vs. XYZ Report
n Weeks Comparison
ABC - January 30, 2011 - February 26, 2011 
XYZ - October 31, 2010 - November 27, 2010"

以上代码无效。请为同样的方法提出一个好的方法

1 个答案:

答案 0 :(得分:2)

Dim campaign_date As Variant
campaign_date = "ABC vs. XYZ Report " & vbCrLf  & _
"n Weeks Comparison" & vbCrLf  & _
"ABC - January 30, 2011 - February 26, 2011 " & vbCrLf & _
"XYZ - October 31, 2010 - November 27, 2010"

下划线_是行继续符,&符号&连接字符串,关键字vbCrLf是换行符(Cr =回车符,Lf =换行符)。< / p>