0

I'm experiencing an error with using the End method of the range object.

The code below is an excerpt from my program, and when I get to the last line I get the following error: "Application defined or Object Defined error"

Sub DataGroup(testCell, j, k)
    Dim archive As Range
    Set dataCellsA = Worksheets("DATA").Range("B2")
    Set dataCellsB = Worksheets("DATA").Range("I2")
    For i = 0 To 30
        Set currentLine = testCell.Offset(i, 0)
        Set archive = Worksheets("ARCHIVE").Range("B4").End(x1Down)

However, in a later portion of my program I have what appears to be the same implementation, but I don't receive any errors with this portion.

    Set dataCellsA = Worksheets("DATA").Range("C2")
    Set dataCellsB = Worksheets("DATA").Range("J2")

    Dim lastCellA As Range
    Dim lastCellB As Range

    Set lastCellA = dataCellsA.End(xlDown)
    Set lastCellB = dataCellsB.End(xlDown)

Whats the difference between the two? I'm making sure to declare my variables as ranges, and I'm careful to use the "Set" prefex to ensure that it is an object, and not the value.

5
  • Is "ARCHIVE" correctly spelled? And is it in the same workbook as the code? Commented Mar 26, 2013 at 20:27
  • 10
    I see x1Down where you should have xlDown!! Commented Mar 26, 2013 at 20:28
  • 1
    And beware: x1Down is not xlDown (very slight difference) Commented Mar 26, 2013 at 20:29
  • @KazJaw care to change it into an answer and get this question "resolved"? Commented Mar 26, 2013 at 22:15
  • @KazJaw Oh wow.. thanks for that one. I would have never noticed such a small detail Commented Mar 26, 2013 at 22:40

1 Answer 1

2

So, here is the answer: you have x1Down where you should have xlDown (1 instead of l)

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.