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

Regex extract string and find highest number from Google Sheet column

I need to find the latest internal code in a long google sheet, so i know the next number to use in a equipment database… Im new to Regex.

My data looks like this:

chggpr-001
chggpr-001
chggpr-001
chggpr-001
chggpr-001
chggpr-001
chggpr-001
chgaa-001
chgaa-001
chgaa-001
chgaa-001
chgaa-001
chgaa-001
chgaa-001
bataa-001
chgusb-001
camacc-015
camacc-016
lensfe-002
vidmon-002
lensfe-003
lensfe-004
cam-003

let’s say i input the string "camacc" into field B1, i want B2 to return 017, because thats the next number of that code available. This way i know i need to add the new items to that number..

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

Right now i’m walking blindly, but this regex seems to work in the editor: camacc\-(\d+)

In google sheets: =arrayformula(MAX(0+iferror(regexextract(B2:B580, "chggpr\-(\d+)"))))
that does not work…

Any tips on how to regex out the string based on cell input, then get the max value?

>Solution :

You can try:

=TEXT(MAX(INDEX(--IFNA(REGEXEXTRACT(A:A,B1&"-(\d+)"))+1)),"000")

enter image description here

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