VBA fuctions

mevikasjain

New Member
Joined
Jun 26, 2011
Messages
10
Create a custom vba function in cell which will extract only the numbers from cell shaded with yellow (the result should be 342356 in the below case)


a3b423fgh56


PLs help me...
 

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.
Try like this

Code:
Function nos(r As Range) As Long
Dim i As Long, s As String
For i = 1 To Len(r.Value)
    If IsNumeric(Mid(r.Value, i, 1)) Then s = s & Mid(r.Value, i, 1)
Next i
If s = "" Then
    nos = 0
Else
    nos = CLng(s)
End If
End Function

Excel Workbook
AB
1a3b423fgh56342356
Sheet2
 
Upvote 0
Here is a function (it can be used as a UDF if needed) that will do what you asked...
Code:
Function Digits(ByVal S As String) As Long
  Dim x As Long
  For x = 1 To Len(S)
    If Not Mid(S, x, 1) Like "#" Then Mid(S, x) = " "
  Next
  Digits = Replace(S, " ", "")
End Function
 
Upvote 0
Posted a number of times before, it's assignment time !!
Code:
http://www.mrexcel.com/forum/showthread.php?t=560077
 
Upvote 0
Posted a number of times before, it's assignment time !!
In that case, I hope the OP chooses to use my posted function... his/her instructor will surely know they didn't come up with that code on their own.:biggrin:
 
Upvote 0
Code:
[COLOR="Blue"]Function[/COLOR] ExtractDigits(Str [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]String[/COLOR]) [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]String[/COLOR]
    Application.Volatile
    [COLOR="Blue"]Dim[/COLOR] m [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]Object[/COLOR]
    [COLOR="Blue"]With[/COLOR] CreateObject("VBScript.RegExp")
        .Global = [COLOR="Blue"]True[/COLOR]
        .Pattern = "\d+"
        [COLOR="Blue"]For[/COLOR] [COLOR="Blue"]Each[/COLOR] m [COLOR="Blue"]In[/COLOR] .Execute(Str)
            ExtractDigits = ExtractDigits & m.Value
        [COLOR="Blue"]Next[/COLOR]
    [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]With[/COLOR]
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Function[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,756
Members
452,940
Latest member
rootytrip

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