LAMBDA adds strange characters when named

lrobbo314

Well-known Member
Joined
Jul 14, 2008
Messages
3,929
Office Version
  1. 365
Platform
  1. Windows
I am trying to write a function that generates passwords.

As you can see below, if I just have the LAMBDA in the workbook, it works as expected.

But, when I define a name with the LAMBDA, the result has odd characters added into it that weren't in the second argument. In this example, there is an errant backslash, but I've seen [, {, }, ], and ` inserted into the result.

Is there a bug or something?

Book4
ABC
1Length16
2Special Characters@#$%^&
3
4
5
6@9I\lYt^6j#&%<3$
7&L^$06@GF9r1cm#%
Sheet1
Cell Formulas
RangeFormula
B2B2="@#$%^&"
C6C6=PWD(B1,B2)
C7C7=LAMBDA(total_length,special,LET(sat,LAMBDA(a,n,TAKE(SORTBY(a,RANDARRAY(ROWS(a))),n)),msc,total_length-LEN(special),num_len,ROUNDUP(msc/3,0),rem,msc-num_len,UoL,ROUNDUP(rem/2,0),last,rem-UoL,scl,MID(special,SEQUENCE(LEN(special)),1),uc,CHAR(ROW(65:90)),lc,CHAR(ROW(97:122)),nl,CHAR(ROW(48:57)),sn,sat(nl,num_len),io,RANDBETWEEN(0,1),su,IF(io,sat(uc,UoL),sat(uc,last)),sl,IF(io,sat(lc,last),sat(lc,UoL)),sc,sat(scl,ROWS(scl)),all,VSTACK(sc,sl,su,sn),TEXTJOIN("",,sat(all,ROWS(all)))))(B1,B2)


Excel Formula:
=LAMBDA(total_length,special,
    LET(
        sat,LAMBDA(a,n,TAKE(SORTBY(a,RANDARRAY(ROWS(a))),n)),
        msc,total_length-LEN(special),
        num_len,ROUNDUP(msc/3,0),
        rem,msc-num_len,
        UoL,ROUNDUP(rem/2,0),
        last,rem-UoL,
        scl,MID(special,SEQUENCE(LEN(special)),1),
        uc,CHAR(ROW(65:90)),
        lc,CHAR(ROW(97:122)),
        nl,CHAR(ROW(48:57)),
        sn,sat(nl,num_len),
        io,RANDBETWEEN(0,1),
        su,IF(io,sat(uc,UoL),sat(uc,last)),
        sl,IF(io,sat(lc,last),sat(lc,UoL)),
        sc,sat(scl,ROWS(scl)),
        all,VSTACK(sc,sl,su,sn),
        TEXTJOIN("",,sat(all,ROWS(all)))
    )
)
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
It looks like the problem is the relative ROW references - which are vulnerable anyway if you start adding or deleting rows to the worksheet.

Given you have 365, why not change ROW(65:90) to SEQUENCE(26,,65), etc
 
Upvote 1
Solution
Oh, that totally makes sense. Thanks, that was driving me crazy.
 
Upvote 0

Forum statistics

Threads
1,216,753
Messages
6,132,514
Members
449,731
Latest member
dasda34

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