(e-mail address removed) explained on 2/27/2012 :
I have selected a few rows that contain text on a worksheet. I would like to
assign the text in these rows to a variable so that I wind up with a text
string in the variable. I can assign the range to an array and then step
through the array and build my text string, or I can copy the selection and
assign the clipboard contents to a variable. Both of these methods work and
achieve the desired result, but they seem unwieldy. There must be a simpler
way to do this. Can someone point me in the right direction?..Thanks, Ron
If the text is broken into several cells on each row then there's no
'simple' solution such that the text could be directly assigned to a
string variable.
Assigning the range to a variant variable results in a 2D array that
you'll have to iterate for each element of text...
Dim vTextIn As Variant
vTextIn = <SelectedRange>
Dim i&, j& 'as long
Dim sTextOut$ 'as string
For i = LBound(vTextIn) To UBound(vTextIn) '#rows
'Join the text with a space or other delimiter as desired
For j = LBound(vTextIn, 2) To UBound(vTextIn, 2) '#cols
sTextOut = sTextOut & " " & vTextIn(i, j)
Next 'j
Next 'i
'Trim the leading space
sTextOut = Mid$(sTextOut, 2)
I don't use the clipboard object for this type of process and so I
can't offer any advice on that<g>.
--
Garry
Free usenet access at
http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion