Excel:返回不同表格中相同单元格的结果

在同一个工作簿中使用相同的模式和相同的表格,我有不同的表格。 我需要检查这些表单中的单元格值以评估条件并返回其值。

例如:Sheet1到Sheet9中的单元格B2始终是一个数字,在另一个表单中,我需要知道这些数字中的哪些数字less于5.然后返回具有值的数组。

这里是VBA的解决scheme。 编辑我在macros的顶部调用的行。

  Option Explicit Sub get_from_sheets() Dim cell_values(), threshold As Double Dim source_cell, output_first_cell, output_sheet As String Dim num_sheets, start_sheet, end_sheet, a As Integer Dim out_rw, out_cl As Integer source_cell = "B2" 'fill in this start_sheet = 10 'fill this end_sheet = 13 'fill this output_sheet = "Sheet14" 'fill this output_first_cell = "A1" 'fill this threshold = 5 'fill this out_rw = Range(output_first_cell).Row out_cl = Range(output_first_cell).Column ReDim cell_values(end_sheet) For a = start_sheet To end_sheet cell_values(a) = Sheets("Sheet" & a).Range(source_cell) Next a For a = start_sheet To end_sheet If cell_values(a) < threshold Then Sheets(output_sheet).Range(Cells(out_rw, out_cl), Cells(out_rw, out_cl)) = cell_values(a) out_rw = out_rw + 1 End If Next a End Sub