How to Convert MS Excel Formula to VBA Code

Jasmine send us an email with the following query:
I’m learning Excel VBA. How can I convert a standard formula like the one below to Excel VBA?
=COUNTIF(A1:A10,”>=700″)-COUNTIF(A1:A10,”<=300″)

We have discussed the countif function in detail. It counts the items based on a specific criteria. Now let’s see how we can convert this countif function into VBA code. We have also attached the converted code to a command button so that the macro’s use becomes even more user-friendly.

Watch the Excel training video below to see how the conversion of the excel formual to VBA code or macro is done:

2 thoughts on “How to Convert MS Excel Formula to VBA Code”

1. vishant panchal

how to excel vba userform create textbox value insert to empty row and “A to I” merge to columns and this row color and font size change,bold.
pls., give this ans.

vishant panchal

2. Jepal Shah

=INDEX(DATA!\$D\$2:\$O\$19,MATCH(\$A\$2&\$C\$6,DATA!\$B\$2:\$B\$19&DATA!\$A\$2:\$A\$19,0),MATCH(A8,DATA!\$D\$1:\$O\$1,0),1)

convert excel formula to VBA