0

I have defined cells inside of two separate arrays. (i.e. source_arr = ("B4","B5"...) and target_arr = ("B5","B6")

I want to loop through both arrays and set the value of the target workbook cells equal to that of the source workbook cells. Right now it sets all the cells equal to one value.

 For i = LBound(source_array) To UBound(source_array)
For j = LBound(target_array) To UBound(target_array)
Data = source_workbook.Sheets("Questionnaire").Cells(source_array(i)).Value
target_workbook.Sheets("Questionnaire").Cells(target_array(j)).Value = Data
Next j
Next i
3
  • You may not be needing two arrays at all. Could you post a screenshot of your data? Commented Oct 13, 2017 at 14:48
  • maybe like target_arr = array("B5","B6") Commented Oct 13, 2017 at 14:48
  • If the arrays are isomorphic, only one loop is required. Commented Oct 13, 2017 at 14:56

1 Answer 1

2

You only need to one loop. And you want Range not Cells:

For i = LBound(source_array) To UBound(source_array)
    Data = source_workbook.Sheets("Questionnaire").Range(source_array(i)).Value
    target_workbook.Sheets("Questionnaire").Range(target_array(i)).Value = Data
Next i
Sign up to request clarification or add additional context in comments.

1 Comment

I did manage to fix the Range part on my own as soon as I posted the question...*rolls eyes* However for some reason I was thinking I needed 2 loops! Such a bozo, I was over thinking it. Thanks for the help it works perfect.

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.