【发布时间】:2018-05-12 18:18:14
【问题描述】:
根据我在这个网站上找到的一个例子,我做了以下过程。它仅将数组的第一个元素打印到整个范围中,而不是将每个元素打印到范围的每个单元格中。你知道我做错了什么吗? 谢谢, 崩溃
i = 2
Do Until Cells(i, 1) = "" 'loops through IDs in 1st column of spreadsheet
If Cells(i, 1) > "" Then 'if it finds an ID
GoSub CommentsColor 'sub that calculates a color -> thisColor
End If
ReDim Preserve colors(i - 2) 'start array at zero
colors(i - 2) = thisColor 'populate array
thisColor = "" 'clear variable
i = i + 1 'go to next ID in 1st column of spreadsheet
Loop
'set range
Set colorData = ActiveWorkbook.Worksheets("Movement_Data").Range(Cells(2, thisCol), Cells(i - 1, thisCol))
colorData.Value = colors 'print array to worksheet
【问题讨论】:
-
cpearson.com/excel/ArraysAndRanges.aspx 你可能需要 Application.Transpose(colors) 。不确定尺寸。见链接。
-
我无法将您的评论标记为正确,但确实如此。我改变的只是 Application.Transpose(colors) 并且它有效。
-
没问题 ;-)