Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

excel - Remove non-numeric characters from numeric fields without loop

I have read some topics explaining how to do this, which would be incredibly slow. The explanation is here: https://www.extendoffice.com/documents/excel/651-excel-remove-non-numeric-characters.html

It involves iterating through each cell in a range and then iterating through the characters in the field and removing them if they do not match [0-9].

Any suggestions to do this more efficiently?

One that comes to mind is loading the cell contents into an array, iterating through it, and splitting each entry into its own array to iterate through.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

No need for VBA or for looping. An excel formula can achieve what you want.

=NPV(-0.9,,IFERROR(MID(A1,1+LEN(A1)-ROW(OFFSET(A$1,,,LEN(A1))),1)%,""))

This is an array formula. You have to press Ctrl + Shift + Enter

enter image description here

Explanation:

Each term is multiplied by the inverse of (1+rate)^n, where n is the nth term in the series.

By using different values for rate, we can get different results. In this case, using -0.9 gives us 1 + rate = 1 + -0.9 = 0.1.

Result: {0.1;0.01;0.001;0.0001;0.00001}
Inverse of above: {10;100;1000;10000;100000}
Also NPV skips text values which contributes to the above

Disclaimer: I did not come up with this formula. I had seen this formula long time ago and simply fell in love with it. Since then it has been a part of my databank.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...