Formula to copy partial content of a cell?

G

Guest

Guest
Question:
I am wondering is there an excel formula to copy one partial content of a cell to another cell?
eg. Copy 90 from Weight-90 in a cell to another cell
Thanks in advance
 
How about a User-Defined Function?

If you put this into a module in your workbook, you can use the function like this:

=ExtractNum(A1)

Code:
Public Function ExtractNum(rng As Range) As Double

    Dim strTemp As String
    
    strTemp = rng.Text
    Do While Not IsNumeric(Left(strTemp, 1))
        strTemp = Right(strTemp, Len(strTemp) - 1)
    Loop
    
    On Error Resume Next
    ExtractNum = Val(strTemp)
    
End Function

Hope this helps,

Russell
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
WOW! this is getting huge!

Why not just:


=SUBSTITUTE(D14,"kg","")*1

Or

=SUBSTITUTE(SUBSTITUTE(D2,"kg",""),"Weight=","")*1

If it actualy contains the text "Weight=" as well.
 
Upvote 0
On 2002-03-12 09:45, Russell Hauf wrote:
How about a User-Defined Function?

If you put this into a module in your workbook, you can use the function like this:

=ExtractNum(A1)

Code:
Public Function ExtractNum(rng As Range) As Double

    Dim strTemp As String
    
    strTemp = rng.Text
    Do While Not IsNumeric(Left(strTemp, 1))
        strTemp = Right(strTemp, Len(strTemp) - 1)
    Loop
    
    On Error Resume Next
    ExtractNum = Val(strTemp)
    
End Function

Hope this helps,

Russell

Note that if your cell has 2 numbers in it that are separated by text (ex: Weight=90kg20mg), it will only return the first number.

-rh
 
Upvote 0
On 2002-03-12 08:19, Anonymous wrote:
Question:
I am wondering is there an excel formula to copy one partial content of a cell to another cell?
eg. Copy 90 from Weight-90 in a cell to another cell
Thanks in advance

Care to post a few examples of text values from which you want to extract the num part?

It's important to know whether there is any kind of regularity in the entries, which could be exploited by a formula.
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,317
Members
449,081
Latest member
tanurai

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top