Splitting a range with several cells

consth21

New Member
Joined
Feb 1, 2005
Messages
25
I was wondering if anyone could help me with this code. I am trying to take a couple of cells (A1:A3) and put them into different cells, 1 right after another. When I try this with the code below, it only does the range of A1.

Sub wordbrk()
Dim x, c As Range, y As Integer
x = Split(Range("A1:A3"), " ")
For Each c In Range("H1:L100")
If y > UBound(x) Then Exit For
c = Trim(x(y))
y = y + 1
Next
End Sub

Thank you!!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
I get an error in the Split() line, because

Range("A1:A3")

returns a Variant() array, not a string, as Split() expects... try using something like

x = Split(Range("A1").Value & " " & Range("A2").Value & " " & Range("A3").Value, " ")
 
Upvote 0
Great that worked!! There is one problem though. When I did it, it stuck the print outs together and only seperated them by one cell instead of making like A2 go to the next row. Can I change this?
 
Upvote 0

Forum statistics

Threads
1,203,242
Messages
6,054,349
Members
444,717
Latest member
melindanegron

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