Read until the space

iggydarsa

Well-known Member
Joined
Jun 28, 2005
Messages
1,647
Hi everyone,

In Vba how can I read partial strings?

lets say I have "abc 123" (there is space after "abc"), and this string is in cell A1 in Sheet1. I want to read the data UNTIL THE FIRST SPACE, so that I can assign "abc" to my variable.

How can I do that?

Thanks
 

Some videos you may like

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

BrianB

Well-known Member
Joined
Feb 17, 2003
Messages
8,127
Code:
Sub test()
    Dim MyString1 As String
    Dim MyString2 As String
    MyString1 = "abc 123"
    s = InStr(1, MyString1, " ", vbTextCompare)
    MyString2 = Left(MyString1, s - 1)
    MsgBox (MyString2)
End Sub
 

iggydarsa

Well-known Member
Joined
Jun 28, 2005
Messages
1,647
Thnx Brian,

Now I will try to adapt according to my code... I hope it works
 

Watch MrExcel Video

Forum statistics

Threads
1,118,678
Messages
5,573,618
Members
412,539
Latest member
itchy00
Top