converting excel formula in vba code

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,227
Office Version
  1. 2010
Platform
  1. Windows
Hi, Please can you help me i would like to convert the below excel formula into vba code, can you help me please? thank you for your time.

Code:
=COUNTIFS(CMEXPORTINPUT!B:B,"Buckinghamshire",CMEXPORTINPUT!H:H,"Pending")
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Something like this?

Code:
Sub CountIF_VBa()
Dim CI As Integer


CI = Application.WorksheetFunction.CountIf(Worksheets("CMEXPORTINPUT").Range("B:B"), "Buckinghamshire", Worksheets("CMEXPORTINPUT").Range("H:H"), "Pending")
End Sub
 
Last edited:
Upvote 0
Hi thankyou where will i put this code please, in a Module or in the sheet?
 
Upvote 0
Thank you, how do i get the information to go into a certain cell for example B10? and do i have to run the module?
 
Upvote 0
Can we ask why you want to turn this into VBA?
 
Upvote 0
hi its bit of a long story, but basically i dont want someone to wipe my excel formula in error, and i cant protect just the one cell as it doesnt update another line on same sheet if protected
 
Upvote 0
Code:
Sub CountIF_VBa()
Dim CI As Integer


CI = Application.WorksheetFunction.CountIf(Worksheets("CMEXPORTINPUT").Range("B:B"), "Buckinghamshire", Worksheets("CMEXPORTINPUT").Range("H:H"), "Pending") 

Worksheets("CMEXPORTINPUT").Range("B10").value = CI[COLOR=#333333]End Sub[/COLOR]
 
Last edited:
Upvote 0
hi thank you, when i run the code i get a compile error on .CountIf, please can you advise? and thank you for your help.
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,253
Members
448,556
Latest member
peterhess2002

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