下面的公式应计算所有符合条件的值的模式。
唯一的问题是,而不是数组公式变为“ M2 = etc”,“ M3 = etc”,“ M4 = etc”,所有值均为“ M2”,这与数组应“填充”无关。 “
Sub ModeColumn()
Dim wb As Workbook, ws As Worksheet, LastRow As Long
Set wb = ThisWorkbook
Set ws = Worksheets("Data")
ws.Cells(1, 15) = "MODE"
LastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row 'Finds the bottom populated row
With ws.Range(ws.Cells(2, 15), ws.Cells(LastRow, 15))
.FormulaArray = "=IFERROR(MODE(IF(RC[-2]=AllSites,R2C12:R" & LastRow & "C12)),""N/A"")"
End With
End Sub
请注意,我是通过从可怕的Selection
,Active
等录制的宏符号转换而得到的