Applying Sumproduct Formula to Cell via VBA Failing

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am trying to find a VBA solution to using the countif function with a closed workbook. With reference to this post, I have attempted to to do this. My attempt is failing, with a #NAME error in the destination cell.
Here is the line of code I'm using to apply the formular to the cell.

Code:
.Cells(1, 30) = "=SUMPRODUCT(('D:\WSOP 2020\[permit_data.xlsx]Activity_Default'!$E2:$E2000=str_func)+0)"

Any suggestions on where I have gone wrong?
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Maybe
VBA Code:
.Cells(1, 30) = "=SUMPRODUCT(('D:\WSOP 2020\[permit_data.xlsx]Activity_Default'!$E2:$E2000=" & str_func & ")+0)"
 
Upvote 0
Solution
Wow! You're fast Fluff!! I appreciate that very much.
I replaced by error ridden line with your's and I'm finding I'm not getting an "Application-defined or object-defined error."
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
Yes, it is ...
Code:
         With Worksheets("thold") 'ws_thold
            .Cells(1, 26) = "=VLOOKUP(""" & pnum & """,('D:\WSOP 2020\[permit_data.xlsx]Permit_Data'!$A3:$E2000),5,FALSE)" 'function
            .Cells(1, 27) = "=VLOOKUP(""" & pnum & """,('D:\WSOP 2020\[permit_data.xlsx]Permit_Data'!$A3:$H2000),8,FALSE)" 'division
            .Cells(1, 28) = "=VLOOKUP(""" & pnum & """,('D:\WSOP 2020\[permit_data.xlsx]Permit_Data'!$A3:$H2000),6,FALSE)" 'league
            .Cells(1, 29) = "=VLOOKUP(""" & pnum & """,('D:\WSOP 2020\[permit_data.xlsx]Permit_Data'!$A3:$H2000),7,FALSE)" 'calibre
            str_func = Worksheets("thold").Cells(1, 26) & Worksheets("thold").Cells(1, 28) & Worksheets("thold").Cells(1, 29) & Worksheets("thold").Cells(1, 27) 'functionleaguecalibredivision
            .Cells(1, 30) = "=SUMPRODUCT(('D:\WSOP 2020\[permit_data.xlsx]Activity_Default'!$E2:$E2000=" & str_func & ")+0)"
            If .Cells(1, 30).Value > 0 Then
                .Cells(1, 31) = "=VLOOKUP(""" & pnum & """,('D:\WSOP 2020\[permit_data.xlsx]Activity_Default'!$E2:$M2000),2,FALSE)" 'base
                .Cells(1, 32) = "=VLOOKUP(""" & pnum & """,('D:\WSOP 2020\[permit_data.xlsx]Activity_Default'!$E2:$M2000),9,FALSE)" 'pitching
            End If
        End With
 
Upvote 0
You marked my post as the solution & said
I'm finding I'm not getting an "Application-defined or object-defined error."
So I asumed that everything was working. Is that the case?
 
Upvote 0
No ... your first solution resolved the original problem, but on testing it, I have a new problem ... the application-defined or object -defined error.

"Not" was supposed to be "Now" ...
 
Upvote 0
The same one ...
Code:
 .Cells(1, 30) = "=SUMPRODUCT(('D:\WSOP 2020\[permit_data.xlsx]Activity_Default'!$E2:$E2000=" & str_func & ")+0)"
 
Upvote 0
What is the exact value of str_func?
 
Upvote 0

Forum statistics

Threads
1,215,544
Messages
6,125,441
Members
449,225
Latest member
mparcado

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