循环中的运行时错误1004用于列的乘法

时间:2016-03-29 02:57:10

标签: excel vba excel-vba

我设计了一个代码,使用if else语句将两列相乘但我在error 1004上得到L = Cells(i, "L").Value因此我需要澄清为什么会发生这种情况。 这是代码!

Sub IfCalculationEq1()

    Dim lastrow As Long

    Application.ScreenUpdating = False
    Dim i As Long
    Dim L As Long
    Dim E As Long


    lastrow = Cells(Rows.Count, "L").End(xlUp).Row

    L = Cells(i, "L").Value
    E = Cells(i, "E").Value

    For i = 3 To lastrow

    If Cells(i, "K").Value = "-" Then

    Cells(i, "N").Value = "-"

    Else

     Cells(i, "N").Formula = "=L*E"

    Application.ScreenUpdating = True

   ' If k is null then no action required or else L1*E3

   End If

   Next

End Sub

1 个答案:

答案 0 :(得分:3)

i在第L = Cells(i, "L").Value行进行了单元化,因此其值为0.单元格数组基于1。