Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

VBA code using sumproduct and indirect functions

I have a sheet containing the following formula in cell F10.
I would like to have a VBA code that will calculate this and place the value in cell

=SUMPRODUCT((WEEKDAY(ROW(INDIRECT(F4&":"&F5)),1)=7)*1)

Cell F4 contains a start date and F5 an end date

I tried the following but get a runtime error 438

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

With ActiveSheet.Range("F10")
        .Value = .Evaluate("SUMPRODUCT((WEEKDAY(ROW(INDIRECT(" & Cells(4, 6) & ":" & Cells(5, 6) & ")),1)=7)*1)")
End With

>Solution :

To fix your specific issue Evaluate is not part of the Range. You need to use the worksheet level instead.

Also it is good to return the .Value2 which will strip the format and return the double.

And you do not need the INDIRECT as you are already using a string

    With ActiveSheet
        Range("F10").Value = .Evaluate("SUMPRODUCT((WEEKDAY(ROW(" & Cells(4, 6).Value2 & ":" & Cells(5, 6).Value2 & "),1)=7)*1)")
    End With
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading