我正在尝试在我的Excel工作表中应用公式,所以我编写了以下代码,但是获得了应用程序定义或对象定义的错误,任何人都可以帮我解决这个问题
我的代码
Sub lastpaydate()
Dim formulastring As String
Dim lastRow_sht3, lastRow_sht8 as long
Dim i and h as integer
h= 0
lastRow_sht3 = Sheet3.Range("A" & Rows.Count).End(xlUp).Row 'find last cell from payment sheet
lastRow_sht8 = Sheet8.Range("A" & Rows.Count).End(xlUp).Row 'find last cell from Reports_Output Sheet
For i = 4 To lastRow_sht8
formulastring = "=IF" & "(MAX(IF(Payments!$A$4:$A$" & lastRow_sht3 & "=" & "A" & i & "),Payments!$B$4:$B$" & lastRow_sht3 & "))=0" ' & "," & Chr(34) & Chr(34) & "," & "MAX(IF(Payments!$A$4:$A$" & lastRow_sht3 & "=" & "A" & i & "),Payments!$B$4:$B$" & lastRow_sht3 & ")))"
Msgbox formulastring
Debug.Print formulastring
Sheet8.Cells(4 + h, 9).FormulaArray = formulastring
h = h + 1
Next i
End Sub
我在msgbox中获得了正确的公式,但是在更新表中的公式获取应用程序定义错误时,我无法找到问题