考虑:
Cells(2, "Q").Formula = "=COUNTIF(P$1:P1,P2)=0"
当我有一个保存值的变量时,如何插入这些公式?
有时我必须从 3550 行和 4000 行开始公式。这取决于数据。好吧,当我用谷歌搜索时,我什么也没找到。他们都使用相同的公式,但我需要插入countif
特定单元格的函数可能为 300 或 500 - 这取决于变量值。
Cells(count,"Q").formula = "=COUNTIF(cells($1,"P"):cells(count-1,"P"),cells(count,"P))=0"
是这样吗?好吧,我尝试了一些方法,但最终还是用红色突出显示了这条线。如何将这些公式与变量一起插入?
尝试这个:
'case 1: if you know the destination range
Range("Q2").Formula = "=COUNTIF(P$1:P1,P2)=0"
Range("Q2").Copy Destination:=range("Q3:Q500")
'case 2: if the destination range is a variable
'minRow is a Long >= 1
Range("Q" & minRow + 1).Formula = "=COUNTIF(P$" & minRow & ":P" & minRow & ",P" & minRow + 1 & ")=0"
Range("Q" & minRow + 1).Copy Destination:=Range("Q" & minRow + 1 & ":Q" & maxRow)
参考:伊松的回答堆栈溢出问题当公式随着行数的增加而不断变化时,如何将公式插入到单元格中?.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)