Split string query

vinny2984

Board Regular
Joined
Sep 22, 2008
Messages
202
I have ben playing with a bit of code to split up a string and take the part string for another purpose.
The code below, finds the bit of string I want but what I really need to do is then ammend the initial string to make it minus the part string.

HTML:
Dim myStr As String
myStr = Range("A2").Value
Range("K2").Value = Split(myStr, " ")(0)

The code above does take the first part of the string up to a space and puts it in K2.

I'm now tryimng to find a way to make
Code:
mystr=mystr -Split(myStr, " ")(0)   'doesn't work

but i can' find a way to make that work

any ideas would be really helpful
thanks
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try this:

Code:
Sub a()

mystr = Range("A2").Value

y = Right(mystr, Len(x) - Application.WorksheetFunction.Find(" ", mystr))


End Sub
 
Upvote 0
Re: Split string - Solved

Thanks thats brilliant. below is the variation I've used

HTML:
myStr = Right(myStr, Len(myStr) - Application.WorksheetFunction.Find(" ", myStr))

many thanks
 
Upvote 0
Re: Split string - Solved

Yeah, sorry about that x. I changed my test code to use your variable names but seems I missed to change that one.
 
Upvote 0
here's the final version, it takes the string and splits it up into sections and palces them in seperate cells.
Many thanks

Code:
Sub Splititup()
Dim myStr As String
myStr = Range("A2").Value 'mystr= "WM GIBBINS,MATT 0.00 744.00 744.00 0.00"
Range("K2").Value = Split(myStr, " ")(0)
myStr = Right(myStr, Len(myStr) - Application.WorksheetFunction.Find(" ", myStr))
Range("K3").Value = Split(myStr, ",")(0)
myStr = Right(myStr, Len(myStr) - Application.WorksheetFunction.Find(",", myStr))
Range("K4").Value = Split(myStr, " ")(0)
myStr = Right(myStr, Len(myStr) - Application.WorksheetFunction.Find(" ", myStr))
Range("K5").Value = Split(myStr, " ")(0)
myStr = Right(myStr, Len(myStr) - Application.WorksheetFunction.Find(" ", myStr))
Range("K6").Value = Split(myStr, " ")(0)
myStr = Right(myStr, Len(myStr) - Application.WorksheetFunction.Find(" ", myStr))
Range("K7").Value = Split(myStr, " ")(0)
myStr = Right(myStr, Len(myStr) - Application.WorksheetFunction.Find(" ", myStr))

End Sub
 
Upvote 0
I know I came late to this party, but here's another potential solution:

Code:
mystr = Trim(Replace(mystr, Split(mystr, " ")(0)&" ", ""))
 
Upvote 0
This might be a slightly better way of weeding out the double spaces potentially remaining if you start nipping bits out the middle of the string, rather than the start

Code:
mystr = Trim(Replace(Replace(mystr, Split(mystr, " ")(0), ""), "  ", " "))
 
Upvote 0
Thanks for both of those alternatives, i'll play around with all the solutions and see which suits the purpose bst
many thanks
 
Upvote 0
Instead of that great long Application.Worksheetfunction.Find you can use vba's InStr() function.

Try something like this:

myStr = Right(myStr, Len(myStr) - InStr(myStr, " "))
 
Upvote 0
Hi

Another option for your sub:

Code:
Sub Splititup()
Dim arrStr As Variant
 
arrStr = Split(Replace(Range("A2").Value, ",", " "))
 
Range("K2").Resize(1 + UBound(arrStr)) = Application.Transpose(arrStr)
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,541
Messages
6,120,110
Members
448,945
Latest member
Vmanchoppy

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