当您拥有值的变量时插入COUNTIF公式 [英] Insert COUNTIF formula when you have variable holding the value

查看:185
本文介绍了当您拥有值的变量时插入COUNTIF公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑:

 单元格(2,Q)。Formula == COUNTIF(P $ 1:P1,P2 )= 0

当我有一个保存值的变量时,如何插入这些公式?



我必须在3550行和4000行的时候启动公式。这取决于数据。那么,当我上网的时候,我什么都没找到。他们都使用相同的公式,但是我需要在特定单元格中插入 countif 函数,可能在300或500 - 它取决于变量值。

= $ COUNC($($ 1,P):cell(count-1) ,P),单元格(count,P)= 0

嗯,我在某些方面尝试过,但是最后还是用红色的方式表现出来,如何用变量插入这些公式?

解决方案

尝试这样:

 'case 1:如果你知道目的地范围
范围(Q2 ).Formula == COUNTIF(P $ 1:P1,P2)= 0
范围(Q2)复制目的地:=范围(Q3:Q500)

'case 2:如果目标范围是一个变量
'minRow是一个Long> = 1
范围(Q& minRow + 1).Formula == COUNTIF(P $& ; minRow&:P& minRow&,P& minRow + 1&)= 0
Range(Q& minRow + 1).Copy Destination:= Range (Q amp; minRow + 1& :Q& maxRow)

参考: Issun's answer to Stack  Overflow question > 当公式随行数增加而不断变化时,如何将公式插入单元格?

>

Consider:

 Cells(2, "Q").Formula = "=COUNTIF(P$1:P1,P2)=0"

How do I insert these formulae when I have a variable holding a value?

I have to start the formula at 3550 row and 4000 row somtimes. It depends on the data. Well, when I googled it, I found nothing. They all used the same formula, but I need to insert the countif function at a particular cell, may be at 300 or 500 - it depends in the variable value.

 Cells(count,"Q").formula = "=COUNTIF(cells($1,"P"):cells(count-1,"P"),cells(count,"P))=0"

Is this the way? Well, I tried in some ways but it's ending up higlighting the line with the red colour. How do I insert these formulae with a variable?

解决方案

Try this:

'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)

Reference: Issun's answer to Stack Overflow question How do I insert the formula into the cell when the formula keeps changing with increase in row?.

这篇关于当您拥有值的变量时插入COUNTIF公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆