我想在我的excel vba程序中应用公式数组,但是我的公式数组字符已经超过255个字符,因此我必须使用replace方法来替换公式。
结果公式数组正确,但是我总是必须使用Ctrl + Shift + Enter激活公式,在这种情况下,其他人可以教我如何做吗? 我想显示正确的公式数组内容而不使用Ctrl + Shift + Enter。
以下是我的代码 我的程序逻辑:当用户单击并更改列时,我将读取单元格内容并将数据存储在名为ItemArray的数组中。
Sub countItem(X, y As Variant)
Dim ItemArray() As String
Dim i As Integer, j, k, m As Integer
Dim theFormulaPart1 As String
Dim theFormulaPart2 As String
Dim theFormulaPart3 As String
Dim theFormulaPart4 As String
If (Cells(X, y) <> "") Then
'###split string and store in array###'
ItemArray = Split(Cells(X, y), "+")
theFormulaPart1 = "=TEXTJOIN(CHAR(10),TRUE,IF("
theFormulaPart3 = ",$B4:$B81,"""" ))"
For j = 0 To UBound(ItemArray)
theFormulaPart2 = theFormulaPart2 & "+" & "((E4:E81=" & ItemArray(j) & ")+0)"
Next j
theFormulaPart4 = "X()" & theFormulaPart2 & "Y()"
With Cells(X + 3, 5)
.FormulaArray = theFormulaPart4
.Replace "Y()", theFormulaPart3
.Replace "X()", theFormulaPart1
End With
End If
End Sub