简单的VBA:计算数组公式或255个字符限制解决方法?

时间:2017-07-07 13:08:51

标签: excel vba excel-vba

我需要将一个.FormulaArray插入到我的工作表中,但它远远超过了255个字符的限制(它是420)。我尝试了.Replace解决方法,但它不起作用。使用.Formula =会将其放入单元格,但它不会计算并生成#VALUE!,因此我必须手动crtl+shift+Enter。 VBA有没有办法复制这个?

.Cells(Application.WorksheetFunction.Match("Red Car", .Range("A:A"), 0), Application.WorksheetFunction.Match(ComboBox1.Value & " " & Year(Date), .Range("A6:BZ6"), 0)).FormulaArray = "=INDEX('" & Root & sourceSheet & ws.Name & " " & "SUM" & " " & monthNumber & "." & lastDay & "." & Format(Now(), "yy") & "'!$D:$D,MATCH(""Dealer1"",'" & Root & sourceSheet & ws.Name & " " & "SUM" & " " & monthNumber & "." & lastDay & "." & Format(Now(), "yy") & "'!$A:$A&'" & Root & sourceSheet & ws.Name & " " & "SUM" & " " & monthNumber & "." & lastDay & "." & Format(Now(), "yy") & "'!$B:$B,0))"

我正在使用的.Replace设置是:

Dim theFormulaPart1 As String
Dim theFormulaPart2 As String

theFormulaPart1 = "=INDEX('" & Root & sourceSheet & ws.Name & " " & "SUM" & " " & monthNumber & "." & lastDay & "." & Format(Now(), "yy") & "'!$D:$D,MATCH(""Dealer1"",'" & Root & sourceSheet & ws.Name & " " & "X_X_X())"
theFormulaPart2 = "&" & "SUM" & " " & monthNumber & "." & lastDay & "." & Format(Now(), "yy") & "'!$A:$A&'" & Root & sourceSheet & ws.Name & " " & "SUM" & " " & monthNumber & "." & lastDay & "." & Format(Now(), "yy") & "'!$B:$B,0))"    

.Cells(Application.WorksheetFunction.Match("Red Car", .Range("A:A"), 0), Application.WorksheetFunction.Match(ComboBox1.Value & " " & Year(Date), .Range("A6:BZ6"), 0)).FormulaArray = theFormulaPart1
.Cells(Application.WorksheetFunction.Match("Red Car", .Range("A:A"), 0), Application.WorksheetFunction.Match(ComboBox1.Value & " " & Year(Date), .Range("A6:BZ6"), 0)).Reaplce "X_X_X())", theFormulaPart2

0 个答案:

没有答案