Partial String

R

Rowan Drummond

Try:

Dim myStr As String
Dim myNewStr As String
myStr = "67890 / 1111"
myNewStr = Right(myStr, 4)
Debug.Print myNewStr

Hope this helps
Rowan
 
M

mjack003

Howdy,

How would I go about deleting entire strings, of variable length,
saving only the last four digits of each? Ex: myStr = 67890 / 1111 and
I want myNEWStr = 1111. I need to automate this in VBA.

Appreciate the help,

Mjack
 
M

mjack003

That works great but I don't think I was very clear. I need everything
after the "/" backslash. So is there a way to omit everything before
that character and save only the remaining part?

Thanks for the input,

Mjack
 
R

Rowan Drummond

Try:

Dim myStr As String
Dim myNewStr As String
myStr = "67890 / 1111"
myNewStr = Mid(myStr, InStr(1, myStr, "/") + 1, Len(myStr))
Debug.Print myNewStr

If want the backslash included in the result then you would remove the
"+ 1" but you would then need to include some error handling incase your
string did not contain "/".

Regards
Rowan
 
Top