簡體   English   中英

數組以循環遍歷單元格值Excel VBA

[英]Array to Loop through Cell Values 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM