首先,我正在尝试编写一个宏程序,让用户可以使用它来查找最接近用户输入的总目标的数字。
文件执行后我收到此错误消息。
有什么建议吗?感谢...
Sub Option1()
Dim c As Long
For c = 5 To 8
Sheet1.Cells(5, c).FormulaArray = _
"=INDEX(MOD(INT((ROW(R2C2:INDEX(C2,2^ROWS(R2C2:R9C2)))-1)/2^(TRANSPOSE(MATCH(ROW(R2C2:R9C2),ROW(R2C2:R9C2)))-1)),2)*TRANSPOSE(R2C2:R9C2),MATCH(MIN(ABS(MMULT(MOD(INT((ROW(R2C2:INDEX(C2,2^ROWS(R2C2:R9C2)))-1)/2^(TRANSPOSE(MATCH(ROW(R2C2:R9C2),ROW(R2C2:R9C2)))-1)),2),R2C2:R9C2)-R1C5)),ABS(MMULT(MOD(INT((ROW(R2C2:INDEX(C2,2^ROWS(R2C2:R9C2)))-1)/2^(TRANSPOSE(MATCH(ROW(R2C2:R9C2),ROW(R2C2:R9C2)))-1)),2),R2C2:R9C2)-R1C5),0),0)"
Next c
End Sub
答案 0 :(得分:0)
您应该直接申请整个范围,而不是每个单元格:
Sub Option1()
Sheet1.Range(Sheet1.Cells(5,5),Sheet1.Cells(5, 8)).Clear
Sheet1.Range(Sheet1.Cells(5,5),Sheet1.Cells(5, 8)).FormulaArray = _
"=INDEX(MOD(INT((ROW(R2C2:INDEX(C2,2^ROWS(R2C2:R9C2)))-1)/2^(TRANSPOSE(MATCH(ROW(R2C2:R9C2),ROW(R2C2:R9C2)))-1)),2)*TRANSPOSE(R2C2:R9C2),MATCH(MIN(ABS(MMULT(MOD(INT((ROW(R2C2:INDEX(C2,2^ROWS(R2C2:R9C2)))-1)/2^(TRANSPOSE(MATCH(ROW(R2C2:R9C2),ROW(R2C2:R9C2)))-1)),2),R2C2:R9C2)-R1C5)),ABS(MMULT(MOD(INT((ROW(R2C2:INDEX(C2,2^ROWS(R2C2:R9C2)))-1)/2^(TRANSPOSE(MATCH(ROW(R2C2:R9C2),ROW(R2C2:R9C2)))-1)),2),R2C2:R9C2)-R1C5),0),0)"
End Sub
或
Sub Option2()
Sheet1.Range("E5:I5").Clear
Sheet1.Range("E5:I5").FormulaArray = _
"=INDEX(MOD(INT((ROW(R2C2:INDEX(R2C3,2^ROWS(R2C2:R9C2)))-1)/2^(TRANSPOSE(MATCH(ROW(R2C2:R9C2),ROW(R2C2:R9C2)))-1)),2)*TRANSPOSE(R2C2:R9C2),MATCH(MIN(ABS(MMULT(MOD(INT((ROW(R2C2:INDEX(R2C3,2^ROWS(R2C2:R9C2)))-1)/2^(TRANSPOSE(MATCH(ROW(R2C2:R9C2),ROW(R2C2:R9C2)))-1)),2),R2C2:R9C2)-R1C5)),ABS(MMULT(MOD(INT((ROW(R2C2:INDEX(R2C3,2^ROWS(R2C2:R9C2)))-1)/2^(TRANSPOSE(MATCH(ROW(R2C2:R9C2),ROW(R2C2:R9C2)))-1)),2),R2C2:R9C2)-R1C5),0),0)"
End Sub