【发布时间】:2022-08-14 11:19:27
【问题描述】:
我有两个公式需要转移到 VBA。
在 Excel 上,我的公式是 =countif(A$2:A2,A2),所以我使用这个公式转移了它,但一切都返回到 1。行没有变成动态的,我只希望显示值。
For a = 2 To lrow
ws.Range(\"T\" & a).Formula = \"=CountIf(A$2&\"\":\"\"&A2)\"\",\"\"&A2)\"
Next a
我在 Excel 中使用的下一个公式是
=IF(COUNTIF(A:A,A2)>Q2,\"Check\",\"Ok\")
我在 VBA 中尝试了这个公式:
For i = 2 to lrow
If Countif(ws.Range(\"A2:A\" & lrow), \"A2\") > ws.Range(\"Q2:Q\", & lrow) Then
ws.Range(\"T\" & i).Value = \"Check\"
Else
ws.Range(\"T\" & i).Value = \"Ok\"
End If
Next i
-
ws.Range(\"T2:T\" & lrow).Formula = \"=CountIf(A$2:A2,A2)\"不需要循环 -
ws.Range(\"S2:S\" & lrow).Formula = \"=IF(COUNTIF(A:A,A2)>Q2,\"\"Check\"\",\"\"Ok\"\")\"将S更改为您想要输出的列。