vba to extract numbers

Bartexcel

New Member
Joined
Sep 27, 2021
Messages
6
Office Version
  1. 2016
Platform
  1. Windows
I need VBA to extract the numbers from a cell where specific alphas precede. example - big 1234 = 1234 or Big 1234 = 1234 or large 1234 = 1234 or grand 4321-01 = 4321-01 or Lg. 5678 = 5678.
 
If you are happy with formula

Book2
ABC
1big 12341234
2Big 12341234
3large 12341234
4grand 4321-014321-01
5Lg. 56785678
6
Sheet1
Cell Formulas
RangeFormula
B1:B5B1=MID(A1,AGGREGATE(15,6,FIND({1,2,3,4,5,6,7,8,9,0,"-"},A1),1),99)
 
Upvote 0
Is it always like: text - space - numbers?

VBA Code:
Sub jec()
 For Each it In Range("A1:A5")
    it.Offset(, 1).Value = Split(it)(1)
 Next
End Sub
 
Upvote 1
Welcome to the Board!

If you always have the number after the last space in your text, this would also work:
Excel Formula:
=TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",100)),100))
 
Upvote 0
If you are happy with formula

Book2
ABC
1big 12341234
2Big 12341234
3large 12341234
4grand 4321-014321-01
5Lg. 56785678
6
Sheet1
Cell Formulas
RangeFormula
B1:B5B1=MID(A1,AGGREGATE(15,6,FIND({1,2,3,4,5,6,7,8,9,0,"-"},A1),1),99)
I'm smiling - only that - Big, big, large, lg. and/or grand are specific text that i look for because users will enter data according to their individualized word preferences in the description, and the descriptions can get very lengthy. #tiredeyes Also it would help to calculate the count of numbers rather than ,99) Thank you.
 
Upvote 0
I'm smiling - only that - Big, big, large, lg. and/or grand are specific text that i look for because users will enter data according to their individualized word preferences in the description, and the descriptions can get very lengthy. #tiredeyes Also it would help to calculate the count of numbers rather than ,99) Thank you.

I don't understand what you are trying to say
Will the formula help or not?
 
Upvote 0
Is it always like: text - space - numbers?

VBA Code:
Sub jec()
 For Each it In Range("A1:A5")
    it.Offset(, 1).Value = Split(it)(1)
 Next
End Sub
Could be. It's more like - Big, big, large, lg. and/or grand are specific text that i look for because users will enter data according to their individualized word preferences in the description, and the descriptions can get very lengthy. #tiredeyes Also it would help to calculate the count of numbers so i get just the number. Thank you.
 
Upvote 0
and the descriptions can get very lengthy.
It would be best if you could show us some different examples of what the data may really look like.
It is best not to oversimplify things when posting your questions, or else you may get answers that work for your oversimplified examples, but not for your real data.
 
Upvote 0
This will probably do

VBA Code:
Function jec(cell As String) As String
 ar = Split(cell)
 For i = 0 To UBound(ar)
   If ar(i) Like "[0-9]*" Then
      jec = ar(i)
      Exit Function
   End If
 Next
End Function

Excel Formula:
=jec(A1)
 
Upvote 0
I don't understand what you are trying to say
Will the formula help or not?
sorry - admin won't allow XL2BB - i need vba or formula to find keywords like "large" then extract the number that follow see image. vba.PNG
 
Upvote 0

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