1

I would like to build an array depending on the size of a list. Therefore I try the following:

Range("D3").Select
Set x = Range(Selection, Selection.End(xlDown))

Dim totalRows As Integer
totalRows = (x.Rows.Count) - 1

Dim strCDRack(0 To totalRows) As String

This however gives me a compile error. Thats strange cause when I replace totalRows by 3 it does work

Range("D3").Select
Set x = Range(Selection, Selection.End(xlDown))

Dim totalRows As Integer
totalRows = (x.Rows.Count) - 1

Dim strCDRack(0 To 3) As String

Any thoughts on how I can make this working

1 Answer 1

1

You basically answered your question yourself already ;) (about the reason of the error, not the solution of course). You can't Dim arrays with variable dimensions (as it says in the error message, more or less).

Use

Dim strCDRack() As String
ReDim strCDRack(0 To totalRows)
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.