Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Loop through Range and Cut and Paste

I have a group of cells that I have selected with the mouse (these cells may
be in a row or column).

CELL1
CELL2
CELL3
CELL4
CELL5


I want to cut and paste the contents of cells 2 through 5 into Cell 1 with
soft returns between each value.

So, I would end up with Cell 1 containing (cells 2 through 5 would now be
empty):

CELL1 <SoftReturn
CELL2 <SoftReturn
CELL3 <SoftReturn
CELL4 <SoftReturn
CELL5 <SoftReturn





  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Loop through Range and Cut and Paste

Kevin,

Sub KevinMergeValues()
Dim myCell As Range
Dim myVal As String

For Each myCell In Selection
myVal = myVal & IIf(myVal = "", "", Chr(10)) & myCell.Value
Next myCell

Selection.ClearContents
Selection(1).Value = myVal
Selection(1).WrapText = True
End Sub

But this won't put a soft return after the end of the last cell's (CELL5 in
your example) value. I don't know why you would want one....

HTH,
Bernie
MS Excel MVP

"Kevin L" wrote in message
...
I have a group of cells that I have selected with the mouse (these cells

may
be in a row or column).

CELL1
CELL2
CELL3
CELL4
CELL5


I want to cut and paste the contents of cells 2 through 5 into Cell 1 with
soft returns between each value.

So, I would end up with Cell 1 containing (cells 2 through 5 would now be
empty):

CELL1 <SoftReturn
CELL2 <SoftReturn
CELL3 <SoftReturn
CELL4 <SoftReturn
CELL5 <SoftReturn







  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Loop through Range and Cut and Paste

Thanks Bernie. It works perfectly.




"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Kevin,

Sub KevinMergeValues()
Dim myCell As Range
Dim myVal As String

For Each myCell In Selection
myVal = myVal & IIf(myVal = "", "", Chr(10)) & myCell.Value
Next myCell

Selection.ClearContents
Selection(1).Value = myVal
Selection(1).WrapText = True
End Sub

But this won't put a soft return after the end of the last cell's (CELL5
in
your example) value. I don't know why you would want one....

HTH,
Bernie
MS Excel MVP

"Kevin L" wrote in message
...
I have a group of cells that I have selected with the mouse (these cells

may
be in a row or column).

CELL1
CELL2
CELL3
CELL4
CELL5


I want to cut and paste the contents of cells 2 through 5 into Cell 1
with
soft returns between each value.

So, I would end up with Cell 1 containing (cells 2 through 5 would now be
empty):

CELL1 <SoftReturn
CELL2 <SoftReturn
CELL3 <SoftReturn
CELL4 <SoftReturn
CELL5 <SoftReturn









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
VBA Loop to Find then Copy & Paste B J Hankinson Excel Discussion (Misc queries) 0 April 15th 09 06:39 PM
Loop Statement through If Not IsEmpty Then Paste into Destination Dandelo Excel Discussion (Misc queries) 7 July 15th 08 10:29 PM
copy,paste and loop through workbook TUNGANA KURMA RAJU Excel Discussion (Misc queries) 0 December 6th 05 12:31 PM
Cut & Paste Loop Allan[_5_] Excel Programming 1 February 3rd 04 07:28 PM
copy and paste loop Dillonstar[_5_] Excel Programming 1 December 11th 03 04:22 PM


All times are GMT +1. The time now is 12:20 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"