Need Help Converting This Excel Formula To VBA

CaliKidd

Board Regular
Joined
Feb 16, 2011
Messages
173
I want to replace several worksheet formulas with their VBA equivalents, but I'm having problems with the conversion syntax. If someone could help me convert one of them, then hopefully I'll be able to tackle the others.

Here's an example Excel formula I have in cell B11:
Code:
=COUNTIF(INDIRECT("'Sheet 1'!K4:K" & 'Sheet 2'!B54),"Pass")+COUNTIF(INDIRECT("'Sheet 1'!K4:K" & 'Sheet 2'!B54),"Fail")

The desired output should look something like:
Range("B11").Formula = "....."

Also, instead of referring to worksheet tab names "Sheet 1" and "Sheet 2", I would like to refer directly to their VBA sheet property names -- Sheet1 and Sheet2, respectively.

Any help?
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Try:
Code:
Sub mssn()
Set ws1 = Sheet1
Set ws2 = Sheet2
With WorksheetFunction
    Range("B11").Formula = .CountIf(ws1.Range("K4:K" & ws2.Range("B54")), "Pass") + _
            .CountIf(ws1.Range("K4:K" & ws2.Range("B54")), "Fail")
End With
End Sub
 
Upvote 0
Thanks, Villy. Cheers!

I tried about 30-40 formula variations (unsuccessfully) before I gave up and posted this. I appreciate your help because none of my ideas were on the right track.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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