在VBA编码错误“1004”中写入Excel公式
我一直执行Excel VBA错误“1004”执行以下公式
点击查看Excel公式解决scheme
在VBA代码中
For i = 5 To lastrow ws2.Cells(i, lastcolumn + 1).Formula = "=DATEVALUE(INDIRECT(LEFT($F$1,1)" & i & "))+TIMEVALUE(INDIRECT(LEFT($H$1,1)" & i & "))" ws2.Cells(i, lastcolumn + 1).NumberFormat = "dd.mm.yyyy hh:mm:ss" Next i
有谁知道如何确保正确编写VBA代码?
如果i
是1你的公式解决
=DATEVALUE(INDIRECT(LEFT($F$1,1)1)) + +TIMEVALUE(INDIRECT(LEFT($H$1,1)1))
你错过了公式中的&
For i = 5 To lastrow ws2.Cells(i, lastcolumn + 1).Formula = "=DATEVALUE(INDIRECT(LEFT($F$1,1) & " & i & "))+TIMEVALUE(INDIRECT(LEFT($H$1,1) & " & i & "))" ws2.Cells(i, lastcolumn + 1).NumberFormat = "dd.mm.yyyy hh:mm:ss" Next i
在N5中单击公式单元格,然后运行以下代码:
Public Sub PrintMeUsefulFormula() Dim strFormula As String Dim strParenth As String strParenth = """" strFormula = Selection.Formula strFormula = Replace(strFormula, """", """""") strFormula = strParenth & strFormula & strParenth Debug.Print strFormula End Sub
看看直接的窗口,并相应地修复你的公式。