Countif在另一张表中多个列

时间:2018-04-19 14:40:34

标签: vba excel-vba excel

如果工作表中列H或R中的单元格为“1”,我希望我的子计数。在“9000 google search”之后,我希望你能帮我解决一下如何做到这一点?

Dim studyboard1 As Long
studyboard1 = Application.WorksheetFunction.CountIf(Sheets("Delayed Students").Range("H:H, R:R"), 1)

我也试过

studyboard121 = WorksheetFunction.CountIf(Worksheets("Delayed Students").Columns("H,R"), "121")

1 个答案:

答案 0 :(得分:0)

你需要分别计算每一个,然后在它们两个时减去:

Dim HCount As Long
HCount = Application.WorksheetFunction.CountIf(Sheets("Delayed Students").Range("H:H"), 1)

Dim RCount As Long
RCount = Application.WorksheetFunction.CountIf(Sheets("Delayed Students").Range("R:R"), 1)

Dim BothCount As Long
'If you want to remove the duplicate count when R and H are 1 then uncomment the following line
'BothCount = Application.WorksheetFunction.CountIfs(Sheets("Delayed Students").Range("R:R"), 1, Sheets("Delayed Students").Range("H:H"), 1)

Dim studyboard1 As Long
studyboard1 = HCount + RCount - BothCount