0

I have 15 names in column A. While trying to ReDim and populate an already declared array, and extracting the elements (names) into column E, the following code gave me hiccups saying that it was run-time error 1004 (application-defined or object-defined error).

Dim f() as string

Private Sub CommandButton1_Click()
    Finalrow = Cells(Rows.Count, 1).End(xlUp).Row
    ReDim Preserve f(Finalrow - 1)

For i = 0 To Finalrow - 1
    f(i) = Sheet1.Cells(i, 1) ''''This line causes the glitch (error 1004)
Next

For i = 0 To Finalrow - 1
    Sheet1.Cells(i, 5) = f(i)
Next

End Sub
0

2 Answers 2

2

The loop variable i starts with 0; this kills the Cells() function.


(there may be other errors)

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

1 Comment

*...since there is no column number zero.
1

Is this academic exercise?

If not then one can easily use:

Private Sub CommandButton1_Click()
Dim FinalRow As Long
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
Sheet1.Range("E1:E" & FinalRow).Value = Sheet1.Range("A1:A" & FinalRow).Value
End Sub

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.