LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 394
Default Extract Values from a String

Thanks everyone for the replies, it is appreciated.
p45cal, it work perfectly, you are a diamond.

All the Best.
Paul

On Aug 28, 10:10 am, p45cal wrote:
Here's your version, minimally adjusted to make it work:

Sub Test()
Dim r 'these three are not integers - Variants if you want
Dim p
Dim q

Set rngDesign = Worksheets("Data").Range("B2")

r = Split(rngDesign.Value, ",") 'you missed out 'Split'
p = Split(r(3), ")=")
q = Split(r(0), "(")

Worksheets("Statistics").Select
Range("E6").Select 'you had an extra double-quote mark
With ActiveCell
.Offset(0, 0).Value = q(1)
.Offset(1, 0).Value = r(1)
.Offset(2, 0).Value = r(2)
.Offset(3, 0).Value = p(0)
.Offset(4, 0).Value = p(1)
End With
End Sub

Now with a few refinements so that it doesn't matter what sheet is the
active sheet when you run it, nor does it change that active sheet.

Sub Test2()
Dim r
Dim p
Dim q

Set rngDesign = Worksheets("Data").Range("B2")

r = Split(rngDesign.Value, ",")
p = Split(r(3), ")=")
q = Split(r(0), "(")

With Worksheets("Statistics").Range("E6")
.Offset(0, 0).Value = q(1)
.Offset(1, 0).Value = r(1)
.Offset(2, 0).Value = r(2)
.Offset(3, 0).Value = p(0)
.Offset(4, 0).Value = p(1)
End With
MsgBox "done" 'remove later
End Sub

"give me a brief description of what your code and variables are actually
doing please"

Well, the
r = Split(rngDesign.Value, ",")
splits the string "LD(24,6,3,6)=163" into an array of strings using the
comma as delimiter, so it results in:
r(0) being "LD(24"
r(1) being "6"
r(2) being "3"
r(3) being "6)=163"

So r(1) and r(2) can be used straight away, leaving r(0) and r(3) to sort out.
The next line:
p = Split(r(3), ")=")
splits r(3) into an array with 2 members, using the ")=" to delimit (hoping
you'll only ever have one of these character combinations in the string):
p(0) being "6"
p(1) being "163 "
both of which can be used 'as is'.

The next line:
q = Split(r(0), "(")
splits r(0) in the same way but uses "(" as a delimiter resulting in:
q(0) being "LD"
q(1) being "24"

Now there are 8 strings in 3 arrays; only the ones you want are then put
into the sheet. Excel seems happy to recognise the strings as numbers once on
the sheet.

--
p45cal



"Paul Black" wrote:
Hi p45cal,


Thanks for the reply, I must have posted as you were. Your Sub does
indeed do what I want.
The thing is the Cell B2 is in a sheet named "Data" and I want the
results to go in a sheet named "Statistics" and in cells E6:E10.
I have had a go at putting this together but unfortunately it does not
work.
It would be appreciated if you could you give me a brief description
of what your code and variables are actually doing please.


Sub Test()
Dim r As Integer
Dim p As Integer
Dim q As Integer


Set rngDesign = Worksheets("Data").Range("B2")


r = (rngDesign.Value, ",")
p = Split(r(3), ")=")
q = Split(r(0), "(")


Worksheets("Statistics").Select
Range(""E6").Select
With Activecell
.Offset(0, 0).Value = q(1)
.Offset(1, 0).Value = r(1)
.Offset(2, 0).Value = r(2)
.Offset(3, 0).Value = p(0)
.Offset(4, 0).Value = p(1)
End With


End Sub


Thanks in Advance.
All the Best.
Paul


On Aug 27, 10:34 pm, p45cal wrote:
That's exactly what my code does. Just run the macro BlaH6.- Hide quoted text -


- Show quoted text -





 
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
Extract a value from mid string XP Excel Programming 5 March 20th 07 05:32 PM
Extract from string mark Excel Discussion (Misc queries) 2 August 8th 06 12:38 PM
extract string owl527[_7_] Excel Programming 3 November 4th 05 10:35 AM
Extract sub string sixbeforedawn Excel Worksheet Functions 2 October 24th 05 09:50 AM
Extract Unique Values, Then Extract Again to Remove Suffixes Karl Burrows Excel Discussion (Misc queries) 23 June 25th 05 10:37 PM


All times are GMT +1. The time now is 02:56 PM.

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

About Us

"It's about Microsoft Excel"