Countif and If functions

MatthewLane412

New Member
Joined
Aug 23, 2017
Messages
24
Hello,

I'm trying to pull data from sheet 1 and insert it into a particular cell in sheet 3. This has worked perfectly however I need to lay down a set of limitations. If Column "I" contains either "666","637", or "639" in a cell I don't want the countif statement to count that row.

Hopefully this isn't confusing.
My countif coding is down below.

Thanks,
Matt


Code:
Sub IncomeStatement()


Dim I As Long
    finRow = Sheet1.Range("A10000").End(xlUp).Row
    
I = 3


Sheet3.Range("B9") = Application.WorksheetFunction.CountIf(Range("AH3:AH" & finRow), "<365")
Sheet3.Range("B8") = Application.WorksheetFunction.CountIf(Range("AI3:AI" & finRow), "<365")
Sheet3.Range("B5") = Application.WorksheetFunction.CountIf(Range("AG3:AG" & finRow), "")
Sheet3.Range("B6") = Application.WorksheetFunction.CountIf(Range("U3:U" & finRow), "<365")




End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Re: Countifs




Thank you for the link. "Countifs" are exactly what I should have been doing. Unfortunately, I am still having trouble, trouble shooting this. When I use the code below, I come up with Zero. I'm still an amateur when I comes to VBA. Any insight you could give me would be much appreciated.

Thanks,
Matt

Code:
Sub IncomeStatement()
Dim I As Long
    finRow = Sheet1.Range("A10000").End(xlUp).Row
    
I = 3
Sheet3.Range("B8") = Application.WorksheetFunction.CountIfs(Sheets("Sheet1").Range("AH3:AH" & finRow), "<365", Range("I3:I" & finRow), "<>666")

End Sub
 
Upvote 0
Re: Countifs

Assuming that both ranges are on sheet1 try
Code:
Sub IncomeStatement()
Dim I As Long
    finRow = Sheet1.Range("A10000").End(xlUp).Row
    
I = 3
With Sheets("Sheet1")
    Sheet3.Range("B8") = Application.WorksheetFunction.CountIfs(.Range("AH3:AH" & finRow), "<365", .Range("I3:I" & finRow), "<>666")
End With
End Sub
AFAIK countifs will not work on multiple sheets.
 
Upvote 0
Re: Countifs

Assuming that both ranges are on sheet1 try
Code:
Sub IncomeStatement()
Dim I As Long
    finRow = Sheet1.Range("A10000").End(xlUp).Row
    
I = 3
With Sheets("Sheet1")
    Sheet3.Range("B8") = Application.WorksheetFunction.CountIfs(.Range("AH3:AH" & finRow), "<365", .Range("I3:I" & finRow), "<>666")
End With
End Sub
AFAIK countifs will not work on multiple sheets.




This worked perfect once I remembered to use the "text to Columns" function. Thank you very much for your time.

Matt
 
Upvote 0
Re: Countifs

Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,790
Messages
6,174,594
Members
452,574
Latest member
hang_and_bang

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top