Using Right() to pull number out of PM#####

zoog25

Active Member
Joined
Nov 21, 2011
Messages
418
Hello all,

I have a log that uses codes to designate a project number. Common style is two letter followed by a string of number. The situation is that i using a macro to run a special report. What i need is to pull the string of numbers of the the coded number in order to run coding. For example i have PM1952. I need to pull the 1952 in order of the string. I know i can use the Right () function in coding but how do i get it to pull all the numbers and stop at the first letter. In this case it would be M. Thank you for any help. Note that the code is held under the following code TPws.Cells(rw,"G"). That is how i have the coding find the particular code. active row, column G.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
If you always have two letters at the start you can use
VBA Code:
Mid(TPws.Cells(rw,"G"),3)

If you could have any number of letters at the start, could you post some examples? It maybe you'd be better of using RegEx, but that is not something I know about.
 
Last edited:
Upvote 0
As of right now, it's always going to be two letters at the beginning. I believe the codes will be TR, PM, PW, or ST. the issue is the numerical string can be anywhere from 1 number to infinite. I'm setting up something up to work and the code won't repeat so it will keep going. Currently one code is at a 4 digit number and another is at a 6 digit number.
 
Upvote 0
In that case you can use Mid as I showed. If you don't specify the number of characters to return it will return everything after the 2nd character.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
2 letter prefix

T202010a.xlsm
ABC
1
2PM19521952
3aa195254195254
4
2c
Cell Formulas
RangeFormula
C2:C3C2=MID(B2,3,99)
 
Upvote 0

Forum statistics

Threads
1,214,630
Messages
6,120,634
Members
448,973
Latest member
ChristineC

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