Extract a string of variable length and position from a cell getting #VALUE!

rsd007

New Member
Joined
Oct 24, 2022
Messages
38
Office Version
  1. 2019
Platform
  1. Windows
Hello,
I am pulling values after special character in a string. In some case I will get the value but if special character is not in the string will get Error #VALUE!

I am using Formula =MID(B1,SEARCH("@",B1)+1,8) in Cell D1

1672698977297.png
 
Thankyou etaf and Rick,
Thankyou for the replies, I am looking / end result as to extract numbers only (without any lower or upper case letters)

1672725412847-png.81942

Cell C1 should be Blank ( does not have @ in)
Cell C2 Should be 2356 ( does have @ and should ignore letter A and yjr )
Cell C3 Should be 66967 ( does have @ and should ignore letter GRR )
Regards
 
Upvote 0

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
i dont think i can help out much further with that question
 
Upvote 0
You totally ignored my suggestion?

VBA Code:
Function jec(xStr As String) As Variant
 With CreateObject("vbscript.regexp")
   .Global = True
   .Pattern = "(.*@\s?)(.*?)((\s.*)|$)"
   If .test(xStr) Then
     jec = .Replace(xStr, "$2")
     .Pattern = "[^0-9]"
     jec = .Replace(jec, "")
   Else
     jec = "no match"
   End If
 End With
End Function


Book1
BCD
1lattice 4X8 vinyl whiteno match
2privacy lattice white type @A2356yjr2356
3Lattice vinyl grey @66967GRR66967
4Ground Contact @456-3449 blabla c 66854563449
5above @96X122139612213
Sheet1
Cell Formulas
RangeFormula
D1:D5D1=jec(B1)
 
Upvote 0
Thankyou etaf and Rick,
Thankyou for the replies, I am looking / end result as to extract numbers only (without any lower or upper case letters)

1672725412847-png.81942

Cell C1 should be Blank ( does not have @ in)
Cell C2 Should be 2356 ( does have @ and should ignore letter A and yjr )
Cell C3 Should be 66967 ( does have @ and should ignore letter GRR )
Regards
In your first message, cell B5 had this in it.. @96X12213 and result you wanted for it was 96X12213. What is the rule concerning letters... why was this "X" retained and the "A" in the second example above removed? If the letter is inside the digits keep it, if it is on the end, remove it?
 
Upvote 0
In your first message, cell B5 had this in it.. @96X12213 and result you wanted for it was 96X12213. What is the rule concerning letters... why was this "X" retained and the "A" in the second example above removed? If the letter is inside the digits keep it, if it is on the end, remove it?
Yes , Letter inside numbers will always be X and yes will be part of the answer so the answer 96X12213 is good. anytime letters outside to be removed like A2356Yjr should be 2356 only. 66967GRR should be 66967.
 
Upvote 0
You totally ignored my suggestion?

VBA Code:
Function jec(xStr As String) As Variant
 With CreateObject("vbscript.regexp")
   .Global = True
   .Pattern = "(.*@\s?)(.*?)((\s.*)|$)"
   If .test(xStr) Then
     jec = .Replace(xStr, "$2")
     .Pattern = "[^0-9]"
     jec = .Replace(jec, "")
   Else
     jec = "no match"
   End If
 End With
End Function


Book1
BCD
1lattice 4X8 vinyl whiteno match
2privacy lattice white type @A2356yjr2356
3Lattice vinyl grey @66967GRR66967
4Ground Contact @456-3449 blabla c 66854563449
5above @96X122139612213
Sheet1
Cell Formulas
RangeFormula
D1:D5D1=jec(B1)
Hello JEC,

Have not ignored your code.
Problem is I have to do this without Vb script.
Thanks
 
Upvote 0
In your first message, cell B5 had this in it.. @96X12213 and result you wanted for it was 96X12213. What is the rule concerning letters... why was this "X" retained and the "A" in the second example above removed? If the letter is inside the digits keep it, if it is on the end, remove it?
Hello Rick,

Any help,

Letter inside numbers will always be X and yes will be part of the answer so the answer 96X12213 is good. anytime letters outside to be removed like A2356Yjr should be 2356 only. 66967GRR should be 66967.
 
Upvote 0

Forum statistics

Threads
1,223,723
Messages
6,174,117
Members
452,545
Latest member
boybenqn

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