How to add a filter to VBA

Romano_odK

Active Member
Joined
Jun 4, 2020
Messages
379
Office Version
  1. 365
Platform
  1. Windows
Good afternoom,

I got the following VBA code.
VBA Code:
Mag1LocAAP.Caption = "AAP" & Chr(10) & Application.CountIf(Range("Locatie[Locatie]"), "=AAP")

I got a a table with the columns H, I and J. The value of column H (Magazijn) has be 1, column I (Locatie) has to be "AAP" and column J (Voorraad) has to be <>0. When all those values match then the line has to be counted
Can this be done?

Thank you for your time and have a great day.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Yes, you can use CountIfs rather than CountIf:

Code:
Application.CountIfs(Range("Locatie[Locatie]"), "=AAP",Range("Locatie[Magazijn]"),1,Range("Locatie[Voorraad]"),"<>0")
 
Upvote 0
Yes, you can use CountIfs rather than CountIf:

Code:
Application.CountIfs(Range("Locatie[Locatie]"), "=AAP",Range("Locatie[Magazijn]"),1,Range("Locatie[Voorraad]"),"<>0")
That is great, thank you. Have a great day.
Yes, you can use CountIfs rather than CountIf:

Code:
Application.CountIfs(Range("Locatie[Locatie]"), "=AAP",Range("Locatie[Magazijn]"),1,Range("Locatie[Voorraad]"),"<>0")
I tried to add this line to the rest but it turns red. What could be the error here?

Private Sub worksheet_change(ByVal target As Range)
Negatief.Caption = "voorraad < 0" & Chr(10) & Application.CountIf(Range("Locatie[Voorraad]"), "<0")
Mag1LocAAP.Caption = "AAP" & Chr(10) & Application.CountIf(Range("Locatie[Locatie]"), "=AAP")
Werkvloer.Caption = "werkvloer" & Chr(10) & Application.CountIf(Range("Locatie[Locatie]"), "=Werkvloer")
Zweg.Caption = "z-weg" & Chr(10) & Application.CountIf(Range("Locatie[Locatie]"), "=z-weg")
'Range("J1").Value = Application.CountIf(Range("Locatie[Voorraad]"), "<0")
Application.CountIfs(Range("Locatie[Locatie]"), "=AAP",Range("Locatie[Magazijn]"),1,Range("Locatie[Voorraad]"),"<>0")
End Sub
 
Upvote 0
You were supposed to replace just the Application.Countif part in the original code line you posted with that Application.Countifs version.
 
Upvote 0
Solution
You were supposed to replace just the Application.Countif part in the original code line you posted with that Application.Countifs version.
Bit late, but thank you for your reply and solution.
 
Upvote 0

Forum statistics

Threads
1,216,105
Messages
6,128,859
Members
449,472
Latest member
ebc9

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