I have an array of alphanumeric data used in application testing, and for certain reasons I need to calculate a sum of occurrences of letters from “a” to “f” in each string (this will be used for further data processing):
02599caa0b600 --> should be 4
489455f183c1fb49b --> should be 5
678661081c1h
66410hd2f0kxd94f5bb
8a0339a4417
f6d9f967ts4af6e
886sf7asc3e85ec
03f1fhh3c3a2am
e491b17638m60
1m8h2m07bhaa4tnhbc4
29ma900a80m96m65
ca6a75f505tsac8
956828db8ts7fd1d
cf1d220a59a7851180e
a8b7852xd9e7a9
b85963fbe30718db9976
39b8kx8f85abb1b6
0xxb3b648ab
a8da75f730d45048
588h69d344
This is what strings look like, their length is about 10-30 symbols, and I suppose to have about 3-5k of them daily for processing. Assumptions and limitations:
- Case of letters does NOT matter (happily).
- The list of letters may change one day, but very much likely still remains a range, e.g. a-k, d-g, etc. – therefore solution should be as much flexible as possible.
- Any temporary calculations / ranges are not prohibited, but the shorter the better.
- I’d prefer pure Excel solution, but in case it’s too complicated – VBA still an option. Nevertheless, complicated Excel formula is better than “2-lines-of-code” VBA – if the 1st works as expected.
Things I’ve tried so far (as I noticed, that practice here is very much welcome):
- Searched through already answered questions, but found no Excel-based solutions for anything similar. Other languages / approaches are not an option (except VBA).
- The best thing I got on my own so far are nested
SUBSTITUTEfunctions, but it’s dirty and very straightforward. Assuming the range may change to c-x that’ll be a nightmare. - I’m not a newbie to Excel, but things like complicated array formulas are still hard nuts for me – alas but true…
Anyway, I do not ask for “ready-to-go” “out-of-box” solution – I ask for help and right direction / approach for self-learning and further understanding of similar problems.
Here’s my option – pretty similar to already posted, but anyway… especially if you’re interested in learning, which is so rare today)
Assuming you have your list starting A2, use the following array formula:
Just as reminder – press CTRL+SHIFT+ENTER instead of usual ENTER.
Some explanations:
CHAR(ROW(INDIRECT(...)))structure.And two more similar “nuts” samples – just for learning purposes.
In case you need to summarize all digits matches – you still may use the above using 0 and 9 as input (digits are chars with 48 to 57 codes starting 0). However, the following more simple solution will go as well:
The trick here is that we may generate numbers 0-9 using array or row numbers 1-10 minus 1 –
ROW(0)would generate an error.Finally, if you need to calculate a sum of all digits in the string – use this:
Here we disintegrate the initial string to letters using
MIDfor every single char, and then test it against being a number usingIFERRORand returning 0 for anything but digit.Last 2 are (obviously) your beloved array nuts)))
I use the above samples in my Excel training for QA stuff (by the way welcome to SE, colleague!), thus demonstrating typical functions / approaches for nuts cracking. Hope that was useful for you as well. However, all the previous answers deserve at least your fair upvote, especially @barry’s nuts-free recipe)
For your convenience sample file is shared: https://www.dropbox.com/s/qo5k479oyawkrzh/SumLettersCount.xlsx
Good luck with your testing)