Problem with VBA Formula/Quotes

Sassbearilla

New Member
Joined
Feb 9, 2022
Messages
7
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
I know this is going to be a simple answer, but I just can't seem to get to it.

What I want is to translate this Excel formula to VBA:

VBA Code:
=SUMPRODUCT(F5:F18/COUNTIF(F5:F18,F5:F18))

I know it's gotta be something like:

VBA Code:
Range("F" & ReportLR + 1) = WorksheetFunction.SumProduct("F5:F" & ReportLR / WorksheetFunction.CountIf("F5:F" & ReportLR, "F5:F" & ReportLR))

Hopefully this is clear enough. Any help is very appreciated!!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi & welcome to MrExcel.
Try it like
Excel Formula:
Range("F" & reportlr + 1) = Evaluate("SumProduct(F5:F" & reportlr & " / CountIf(F5:F" & reportlr & ", F5:F" & reportlr & "))")
 
Upvote 0
Solution
Hi & welcome to MrExcel.
Try it like
Excel Formula:
Range("F" & reportlr + 1) = Evaluate("SumProduct(F5:F" & reportlr & " / CountIf(F5:F" & reportlr & ", F5:F" & reportlr & "))")

Yup, I knew it was simple... ugh. Thank you!

I've been browsing Mr. Excel for a while, gotten a lot of good information here, figured I needed to join finally lol.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
@Fluff Can I reopen this? I think I need to actually input a formula2 formula into the cell, rather than use VBA, but I'm not sure how to accomplish that either.

Pseudocode would look something like this:

Code:
Range("F" & ReportLR + 1).Formula2 = "=SUMPRODUCT(F5:ReportLR/COUNTIF(F5:ReportLR,F5:ReportLR))"

I'm just not sure how to combine the VBA variable and the Excel formula. Thoughts?
 
Upvote 0
Figured it out. Just didn't have my quotes in the right place. *facepalm*

VBA Code:
.Range("F" & ReportLR + 1).Formula2 = "=SUMPRODUCT(F5:F" & ReportLR & "/COUNTIF(F5:F" & ReportLR & ",F5:F" & ReportLR & "))"
 
Upvote 0
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,605
Members
449,089
Latest member
Motoracer88

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