Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Separate String into string + value form

If I have a string " tree1234 ". How can I separate it
into 2 cells " tree " and the most important the " 1234 "
should be in value format. Pls advise.

Johnny
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Separate String into string + value form

Dim lngNum as Long
Dim sStr as String
Dim sStr1 as String

sStr1 = " tree1234 "
sStr = Left(sStr1,5)
lngNum = cLng(Trim(Right(sStr1,5)))

--
Regards,
Tom Ogilvy

"Johnny" wrote in message
...
If I have a string " tree1234 ". How can I separate it
into 2 cells " tree " and the most important the " 1234 "
should be in value format. Pls advise.

Johnny



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Separate String into string + value form


Sub test()
Dim str As String, lng As Long, i As Long

str = "tree1234"
i = 1: Do Until IsNumeric(Mid(str, i, 1)): i = i + 1: Loop
lng = Right(str, Len(str) - i + 1)
str = Left(str, i - 1)
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Johnny" wrote in message
...
If I have a string " tree1234 ". How can I separate it
into 2 cells " tree " and the most important the " 1234 "
should be in value format. Pls advise.

Johnny



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Separate String into string + value form

Given I don't know what all possible values are, I will assume that
tree1234 will always have the same length. Given that, you could try
the following

Public Function doParse(Text As String, RowNdx As Integer)
Range("B" & RowNdx) = Left(Text, 4)
Range("C" & RowNdx) = Right(Text, 4)
End Function

Private Sub Workbook_Open()
Dim RowNdx As Integer

Range("A1:A5").Select
With ActiveSheet.UsedRange
For RowNdx = 1 To 5
doParse Range("A" & RowNdx), RowNdx
Next
End With
End Sub

Given the following information in your spreadsheet (cells A1:A5):
tree1234
tree1235
tree1236
tree1237
tree1238



"Johnny" wrote in message ...
If I have a string " tree1234 ". How can I separate it
into 2 cells " tree " and the most important the " 1234 "
should be in value format. Pls advise.

Johnny

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
separate string Rick Excel Discussion (Misc queries) 8 February 14th 09 03:37 AM
separate two dates from a text string into two separate cells Tacrier Excel Discussion (Misc queries) 3 October 13th 08 08:53 PM
separate numbers out of string joesf16 Excel Worksheet Functions 3 May 2nd 07 07:15 AM
Separate a String of #'s Coal Miner Excel Worksheet Functions 4 July 10th 06 04:47 PM
Separate characters in a string viadisky Excel Discussion (Misc queries) 2 February 1st 06 05:35 PM


All times are GMT +1. The time now is 03:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"