Hello,
I have a situation were i want to extract the 3 digits from a 9 digits field which is located in centre.
For example: In column ‘B’ 110121003, 201322789, 576914857 i want this 121, 322, 914 in Column ‘A’
Is it possible.
Thanks in advance.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Extract Middle Part from Numeric
Not sure it really matters performance wise from a practical standpoint. I have never checked (I imagine it would take thousands, if not hundreds of thousands, calculations to even detect a difference. If I were to speculate I would guess (time-wise): value < 0+ ~ 1* << — .
[My logic is that Value is a built in function set to do this conversion. I suspect the math processes must first use "value" to convert the text before it can work. Addn to me is "standard", multiplication is more complex routine than addn and — [=(-1)*(-1)*] is essentially 2 multiplications so should be double the processing of 1*, but I am just guessing]
In any of the cases the MID function will probably be much slower process than even the –.
Steve
Hi,
Thanks to all for your valuable answers, but now i face a new difficulty if suppose the mid part contains a zero then that gets trimmed in col A.
if its 001 then column A has value of only 1, if its 011 then column A has 11. I want to retain that leading zero’s also.
Please suggest.
Just for fun, a mathematical approach as a UDF?
Public Function Middle3(num As Double) Middle3 = WorksheetFunction.RoundDown(((num / 10 ^ 6) – WorksheetFunction.RoundDown(num / 10 ^ 6, 0)) * 1000, 0) End Function
Maud
Although there is a simpler way of doing this as described in the previous posts, playing with this formula uncovered some interesting properties. Changing the power of 10 and the number of zeros in the multiplication at the end allows manipulation of which values are extracted.
To make it more versatile, parameters for the starting point and length were added to the UDF. Given the above solution, I don’t know if there would ever be a need but if so, the calling cell formula would be:
=middle(num, start, len) e.g. =middle(A1,6,3)
Public Function Middle(num As Double, start As Integer, length As Integer) As Integer Application.Volatile If num > 10 ^ (start – 1) Then Middle = WorksheetFunction.RoundDown(((num / 10 ^ start) – WorksheetFunction.RoundDown(num / 10 ^ start, 0)) * 10 ^ length, 0) End If End Function
I don’t see the need for a UDF, they are much slower than normal excel functions and force teh possible macro warnings. A numeric approach could be done with a normal formula:
=ROUND(MOD(B1,1000000)/1000,0)
But I think that:
=VALUE(MID(B1,4,3))
is more intuitive and without the value, is a more general method.
Steve
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications