VBA: Insert Formula Containing an Asterisk "*"

zero269

Active Member
Joined
Jan 16, 2023
Messages
253
Office Version
  1. 365
Platform
  1. Windows
Hello,

I'm having some trouble with inserting a formula using VBA where the formula contains an asterisk (*).

My original working VBA code is this:
VBA Code:
'Insert Filter Formula
ws.Range("A3").Formula2 = "=LET(x,FILTER(CHOOSECOLS(t_" & Name & _
    ",13,1,2,20,21,9,10,16,18),COUNTIF(l_OnHand,t_" & _
    Name & "[Book Status])),SORT(x,3))"
However, I needed to add a second criteria using * for AND. The following formula just adds *(ISBLANK(t_JohnDoe[Score])) which works with in cell testing:
Excel Formula:
=LET(x,FILTER(CHOOSECOLS(t_JohnDoe,13,1,2,20,21,9,10,16,18),(COUNTIF(l_OnHand,t_JohnDoe[Book Status]))*(ISBLANK(t_JohnDoe[Score]))),SORT(x,3))
Trying to use the following to insert this new formula keeps failing, and I suspect it's due to the * symbol.
Results in runtime error 1004 Application-defined or object-defined error
VBA Code:
'Insert Filter Formula
ws.Range("A3").Formula2 = "=LET(x,FILTER(CHOOSECOLS(t_" & Name & ",13,1,2,20,21,9,10,16,18)," & _
    "COUNTIF(l_OnHand,t_" & Name & "[Book Status]))*(ISBLANK(t_" & Name & "[Score]))),SORT(x,3))"
I've tried separating the asterisk to no avail:
VBA Code:
& "*" &
Any help would be greatly appreciated…
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Looks like you're missing the "(" in front of COUNTIF?
Thanks Stephen, good catch! (y)
Everything is working fine now...
VBA Code:
ws.Range("A3").Formula2 = "=LET(x,FILTER(CHOOSECOLS(t_" & Name & ",13,1,2,20,21,9,10,16,18)," & _
        "(COUNTIF(l_OnHand,t_" & Name & "[Book Status]))*(ISBLANK(t_" & Name & "[Score]))),SORT(x,3))"
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

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