Forum Discussion

AdityaMahajan's avatar
AdityaMahajan
Copper Contributor
May 11, 2020

run time error 1004

Hi, could anyone help me with this problem?

 

Sub ButtonCode()
Dim N As Long
N = Cells(Rows.Count, "C").End(xlUp).Row + 1
Cells(N, "C").Value = (Cells(N - 1, "C").Value) * (1 - Range("Sheet2!E5").Value)

Dim X As Long
X = Cells(Rows.Count, "D").End(xlUp).Row + 1
Cells(X, "D").Value = (Cells(N - 1, "D").Value) * (1 - Range("Sheet2!E9").Value)

Dim Y As Long
Y = Cells(Rows.Count, "E").End(xlUp).Row + 1
Cells(Y, "E").Value = (Cells(N - 1, "E").Value) * (1 - Range("Sheet2!E13").Value)

Dim K As Long
K = Cells(Rows.Count, "F").End(xlUp).Row + 1
Cells(K, "F").Value = (Cells(N - 1, "F").Value) * (1 - Range("Sheet2!E17").Value)

Dim J As Long
J = Cells(Rows.Count, "G").End(xlUp).Row + 1
Cells(J, "G").Value = (Cells(N - 1, "G").Value) * (1 - Range("Sheet2!E21").Value)

Dim L As Long
L = Cells(Rows.Count, "H").End(xlUp).Row + 1
Cells(L, "H").Value = (Cells(N - 1, "H").Value) * (1 - Range("Sheet2!E25").Value)

Dim T As Long
T = Cells(Rows.Count, "I").End(xlUp).Row + 1
Cells(T, "I").Value = (Cells(N - 1, "I").Value) * (1 - Range("Sheet2!E29").Value)

End Sub

4 Replies

    • AdityaMahajan's avatar
      AdityaMahajan
      Copper Contributor

      Cells(N, "C").Value = (Cells(N - 1, "C").Value) * (1 - Range("Sheet2!E5").Value) 

      this and subsequent similar lines are the cause of error

      • bhushan_z's avatar
        bhushan_z
        Iron Contributor

        AdityaMahajan ur code seems fine, I am able to run it in my system.

        Is it possible for u to share the file?

        and I hope u have not renamed the worksheet "sheet2"?

Resources