2

I am having an issue with a "Run-time error '1004': Application-defined or object-defined error. My if then statement is not recognizing one of the objects being compared please help me to understand what I am doing wrong.

Sub Enter_deposits()

    Sheets("Deposits").Activate

    Dim x As Integer
    Dim y As Integer


    For x = 4 To 21
        For y = 10 To 500
            If Sheets("deposits").Range(2, 4).Value = Sheets((Cells(x, 14).Value)).Range(y, 2).Value _
                    And Sheets((Cells(x, 14).Value)).Range(y - 1, 3) = 0 _
                    And Sheets("deposits").Range(x, 15).Value <> Sheets((Cells(x, 14).Value)).Range(y, 3) Then

                Sheets("deposits").Range(x, 15).Copy
                Sheets((Cells(x, 14).Value)).Range(y, 3).PasteSpecial xlPasteValues

            Else

            End If
        Next y
    Next x
End Sub

1 Answer 1

4

You need to understand how the range-object and cell-object work in VBA. If you, for example, want to reference to the value in cell "D2" in the "Deposits"-sheet, you can do this with either:

Sheets("deposits").Range("D2").value

or

Sheets("deposits").Cells(2,4).value

It seems like you are mixing up the use of these two objects in you code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.