VBA: Convert Complex Formula to VBA

zero269

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

I'm looking to see if I can convert a complex formula that I got from @Peter_SSs in this thread:


I was looking into VBA's WorksheetFunction's but LET isn't listed.
This led me to look at one of the other three formulas in that thread. @Phuoc uses just the AGGREGATE function, but after testing it again, I realized it's not finding the first missing number.
So, perhaps there's a way to still use the one provided by Peter?

Excel Formula:
=LET(s,SEQUENCE(1000,,990001),AGGREGATE(15,6,s/ISNA(MATCH(s,B4:B14,0)),1))

Or perhaps there's another way to achieve the same results using VBA?

Thank you,
 
You're welcome. Glad it was useful.

BTW, instead of hard-coding that 1000 in the sequence function, which is likely much larger than required anyway, and since you are using a formal table structure, you could use this instead as it should give exactly the right length sequence.

Rich (BB code):
NextNum = Evaluate("=LET(s,SEQUENCE(ROWS(tblBooks),,990001),AGGREGATE(15,6,s/ISNA(MATCH(s,tblBooks[Quiz],0)),1))")
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
You're welcome. Glad it was useful.

BTW, instead of hard-coding that 1000 in the sequence function, which is likely much larger than required anyway, and since you are using a formal table structure, you could use this instead as it should give exactly the right length sequence.

Rich (BB code):
NextNum = Evaluate("=LET(s,SEQUENCE(ROWS(tblBooks),,990001),AGGREGATE(15,6,s/ISNA(MATCH(s,tblBooks[Quiz],0)),1))")
Thanks Peter,

I meant to ask you about that 1000 value earlier to determine if I would run out of numbers when I reach a thousand, but it slipped my mind.

Changes made and tested; works perfect. (y)

Thanks again Peter...

VBA Code:
Sub EnterNextQuizNumber()

    Dim NextNum As Long
    NextNum = Evaluate("=LET(s,SEQUENCE(ROWS(tblBooks),,990001),AGGREGATE(15,6,s/ISNA(MATCH(s,tblBooks[Quiz],0)),1))")
    ActiveCell.Value = NextNum
    ActiveCell.Offset(1).Select 'Select next cell below
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
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