Reading/Disassembling a String of information

M

mastermind

The code below gathers numbers from a set range and then consolidates
them to one cell:
E F G ... V
1 No 3 ... 1,No,3,...

Sub StrgGen()
Set nana = Range("E12:T12")
Range("V12").ClearContents
increment = 1
For Each c1 In nana
If increment = 1 Then
Range("V12").Value = c1.Value
increment = 2
Else
Range("V12").Value = Range("V12").Value & "," & c1.Value
End If
Next c1
End Sub

I am curious to know if there is a way to disassemble the generated
string. The values of the cells are not restricted and thus the
string will vary in length. Does anyone have any solutions? Any help
will be greatly appreciated.
 
X

XP

Hi,

Open the Visual Basic Editor, type SPLIT, place your cursor anywhere in the
word and press F1.

Also do the same for JOIN.

These are very useful commands for working with strings and they make it
much easier to read in and write out strings stored in memory.

Hope this helps.
 
M

mastermind

Thank you for the information, but I still need some help. I don't
really know what to put in the expression segment of the code. Do you
think that you could give me an example. Using the criteria given in
the initial problem statement.

Split(0, "," , -1) = Range("T13:E13")

Is what I tried and it doesn't work, probably for obvious reasons, but
if you could help me out with an example or further explaination that
would be great. Thank you.
 
R

Rick Rothstein \(MVP - VB\)

First off, Split is a function and, as such, operates on something... you
can't assign anything to it. Second, it takes a single String argument and
produces an array with each element of the array containing the text
occurring between the delimiters, so you would want to give it V13 to
operate on, no E13:T13. Third, you didn't tell us what you wanted to do with
the disassembled values. Here is some code which will put the disassembled
information on Row 25 starting in Column A...

Sub Test()
Dim X As Long
Dim Parts() As String
Parts = Split(Range("V13").Value, ",")
For X = 0 To UBound(Parts)
Range("A25").Offset(0, X).Value = Parts(X)
Next
End Sub

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top