Forum Discussion
hrh_dash
Jun 07, 2022Iron Contributor
Why does my countifs vba returns 0 when the excel formula was previously populating the correct data
Why does my countifs vba returns 0 when the excel formula was previously populating the correct data? I am confused on where did it gone wrong. Sub CalculateCountifs()
Dim ws As Worksheet
...
- Jun 07, 2022
OliverScheurich , thank you for assisting. I am looking up data from another workbook from a different file path.
Tried the code that you have provided; had came up with an error:
Run-time error '6' Overflow.Are you able to code in a way whereby data is look up from another workbook from a different file path?
OliverScheurich
Jun 07, 2022Gold Contributor
Sub countifs()
Dim rngA As Range
Dim rngB As Range
Dim rngC As Range
Dim ws As Worksheet
Dim maxrow As Integer
Set ws = ActiveSheet
maxrow = Range("B" & Rows.count).End(xlUp).Row
Set rngA = Range(Cells(3, 2), Cells(maxrow, 2))
Set rngB = Range(Cells(3, 10), Cells(maxrow, 10))
Set rngC = Range(Cells(3, 11), Cells(maxrow, 11))
ws.Range("C66") = WorksheetFunction.countifs(rngA, ws.Range("C15"), rngB, "GIRO", rngC, "EBS") _
+ WorksheetFunction.countifs(rngA, ws.Range("C15"), rngB, "Credit Card", rngC, "EBS")
ws.Range("C67") = WorksheetFunction.countifs(rngA, ws.Range("C15"), rngB, "GIRO", rngC, "BSCS") _
+ WorksheetFunction.countifs(rngA, ws.Range("C15"), rngB, "Credit Card", rngC, "BSCS")
End SubYou can try these lines of code to calculate countifs.
hrh_dash
Jun 07, 2022Iron Contributor
OliverScheurich , thank you for assisting. I am looking up data from another workbook from a different file path.
Tried the code that you have provided; had came up with an error:
Run-time error '6' Overflow.
Are you able to code in a way whereby data is look up from another workbook from a different file path?