数组循环通过单元格值Excel VBA

我已经定义了两个单独的数组内的单元格。 (即source_arr = ("B4","B5"...)target_arr = ("B5","B6")

我想遍历两个数组,并设置目标工作簿单元格的值等于源工作簿单元格的值。 现在它将所有单元格设置为一个值。

  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 

你只需要一个循环。 而你想要范围不是单元格:

 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