0

Is there a way to copy certain columns from 1 array into 1 range. My problem is that not only the first few columns I want to omit, which should be easy, but also one column in the middle. However I need that column in the middle to validate against. Is there an easy way to skip that column when copying a row from the array into a worksheet? Or is the only way around to make that column the first or the last column when building the array?

The code I have until now is:

For row1 = 2 To TotalRowsMerged
    For row = 2 To TotalRowsAgron
        If Cells(row1, 1) = Agron_Array(row, 1) And Cells(row1, 2) = Agron_Array(row, 2) Then
            Range(Cells(row1,11).Address,Cells(row1,23).Address) = Agron_Array(row,

The columns that I need are: 5 to 13 and 15 to 18, so in total 13, which is the same size as my range.

1 Answer 1

1

You can use Index with an array of column indices:

Range(Cells(row1,11).Address,Cells(row1,23).Address) = _
Application.Index(Agron_Array, row, Array(5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18))
Sign up to request clarification or add additional context in comments.

3 Comments

Range(Cells(row1, 11).Address, Cells(row1, 23).Address) = Application.Index(Agron_Array(row, Array(5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18)))
This is what I made out of it, as it was expecting those brackets after Index, however I get an Run-time error 13: Type mismatch now.
Sorry - I just corrected the typos in my answer. Please try the amended code.

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.