Removing characters from the front of a text string

Brian Feth

New Member
Joined
May 21, 2017
Messages
30
Windows 11, Excel 2021

Can anyone tell me how to remove all of the 29 characters preceding the word VENDOR from the example below using VBA (or any other word in that location, "VENDOR” is an example).
Identifying what is unique to the position in the string; there are 29 preceding characters, there are 4 preceding spaces , and VENDOR is 3 characters after a "/".

Using VBA I want to change String1 into string 2,

String1 = PURCHASE AUTHORIZED ON 01/18 VENDOR Mktp US*R01QK Amzn.com/bill WA

String2 = VENDOR Mktp US*R01QK Amzn.com/bill WA

Help is always appreciated!
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Maybe:
VBA Code:
String2 = Mid(String1, 30)
This will put in String3 from character 30th on
 
Upvote 0
Maybe this:
VBA Code:
String2 = Right(String1, Len(words) - (InStr(1, String1, "/", vbTextCompare) + 2))

I'm confused with the "4 spaces", so I'm doing math on all the preceding character spaces, update as you see fit:
VBA Code:
String2 = Right(String1, Len(String1) - (29 + 4 + 3))
 
Last edited:
Upvote 0
Thank you for your reply. What you suggest is a spread sheet formula
No, that's a vba statement

This will put in String2 from character 30th of String1
 
Upvote 0
Maybe this:
VBA Code:
String2 = Right(String1, Len(words) - (InStr(1, String1, "/", vbTextCompare) + 2))

I'm confused with the "4 spaces", so I'm doing math on all the preceding character spaces, update as you see fit:
VBA Code:
String2 = Right(String1, Len(String1) - (29 + 4 + 3))
 
Upvote 0
String2 = Right(String1, Len(String1) - (29 + 4 + 3))

Returns the characters after the the VENDOR (less a couple of characters). I'm trying to remove everything before the word VENDOR. I'm not sure it this matters in your formula but the vendor may be any number of characters.
 
Upvote 0
I think this is what you want:
VBA Code:
Sub test()
string1 = "PURCHASE AUTHORIZED ON 01/18 VENDOR Mktp US*R01QK Amzn.com/bill WA"
string2 = "VENDOR Mktp US*R01QK Amzn.com/bill WA"

MsgBox Mid(string1, InStr(1, string1, "VENDOR"))
MsgBox Mid(string2, InStr(1, string2, "VENDOR"))
End Sub
 
Upvote 0
No, that's a vba statement

This will put in String2 from character 30th of String1
Sorry, my ignorance is showing. That absolutely works. Thank you so much. I don't want to be greedy but, having derived the string with the VENDOR and everything after it, can you tell me how to get ride of everything after the VENDOR?
 
Upvote 0
I think this is what you want:
VBA Code:
Sub test()
string1 = "PURCHASE AUTHORIZED ON 01/18 VENDOR Mktp US*R01QK Amzn.com/bill WA"
string2 = "VENDOR Mktp US*R01QK Amzn.com/bill WA"

MsgBox Mid(string1, InStr(1, string1, "VENDOR"))
MsgBox Mid(string2, InStr(1, string2, "VENDOR"))
End Sub
The first of line of code does what I want. Thank you. Would it be difficult to remove everything after the word Vendor?
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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