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

How to get the first 3 digits from a cell

So I have got a column and i want to get the first 3 digits only from it and store them in a function called wnS using the split function or any other method that would work. I want to get the first three digits before "_"

I tried doing this but it didn’t work, and I also kept getting "TypeError: wnC.split is not a function"

    var ssh = ssPO.getSheetByName("PO for OR (East).csv")
    wnC = ssh.getRange("N2:N");
    var wnS = wnC.split("_");

enter image description here

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

I would really appreciate an answer

If you need more info please let me know

Thank you.

>Solution :

After you define range, you have to get the values.

function first_3_digs (){
    
        var ssh = ssPO.getSheetByName("PO for OR (East).csv")
        var wnC = ssh.getRange("N2:N");
        var values = wnC.getValues();
        const first_3_digs = values.filter(r => {
            if(r.toString().includes('_')){return r;}
        }).map(r=> r.toString().split('_')[0]);
        console.log(first_3_digs)
    }
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