How to take things from the left (1 Viewer)

phamyh

Registered User.
Local time
Today, 12:46
Joined
Oct 29, 2008
Messages
19
Hi Yall.

I have this long text string:
09 Apr 2010 02:22:32 [] - Ambiguity limit of 32 paths exceeded. Apparent culprits: [a_container_type], [a_item_name]. (Line is: Ointment Vitamin A & D Ointment 1 Pound Jar)\line

I want to get everything to the right of "Apparent culprits:" How do I do this?

Thanks!
 

PaulJR

Registered User.
Local time
Today, 17:46
Joined
Jun 16, 2008
Messages
133
Look up InStr and Right. There are lots of examples on Google of doing this if you search 'VBA string manipulation'.
 

Brianwarnock

Retired
Local time
Today, 17:46
Joined
Jun 2, 2003
Messages
12,701
If using Instr and Right you will want Len as well, I usually use Mid as you can default the length and it takes the rest of the string.

Brian
 

PaulJR

Registered User.
Local time
Today, 17:46
Joined
Jun 16, 2008
Messages
133
Yes, because you need to subtract the total string length from the position where you find 'culprits:'. Here is some code I put together that you can use as a starting point:

I shortened your text string in this example because it wouldn't fit in this window properly.

Sub Macro1()
Dim text As String
Dim righttext As String
Dim position
Dim length1
Dim length2
text = "ed. Apparent culprits: [a_container_type], [a_item"
position = InStr(text, "culprits:")
length1 = Len(text)
length2 = length1 - position - 8
righttext = Right(text, length2)
End Sub
 

Users who are viewing this thread

Top Bottom