Worksheet Function Countifs for resizable range

不打扰是莪最后的温柔 提交于 2021-01-29 06:41:53

问题


I have a table in which I count the records through Worksheet.Function.Countif.

It is nice because it counts the rows using .Rows.Count and so I am alwasy ensured if my table changes the size.

It looks like that (subset of the code):

endrow = .Cells(.Rows.Count, 20).End(xlUp).Row
  ws1.Cells(6, 34).Formula = "=COUNTIF(" & .Range("U6:U" & endrow).Address & ",U6)"  

I wish to write the the worksheet.function formula in the same way as above but for 'Countifs'. In excel, I would type it like that: =COUNTIFS($U$6:$U$144;U6;$T$6:$T$144$;"<>"&T6)

How to write it in vba, using 'endrow' as in the first demonstarted code, i.e. without '144' as the last row but with '& endrow' ? I was trying multiple times, but I cannot get it to work :/

I will appreciate any help.


回答1:


Try this:

ws1.Cells(6, 34).Formula = "=COUNTIFS($U$6:$U$" & endrow & ",U6,$T$6:$T$" & endrow & "," & """" & "<>" & """" & "&T6" & ")"



回答2:


This formula gets the last row of column A:

=IFERROR(LOOKUP(2,1/(NOT(ISBLANK(A:A))),ROW(A:A)),0)


来源:https://stackoverflow.com/questions/54999094/worksheet-function-countifs-for-resizable-range

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!