Select Multiple cells, Combine in a sequence and paste them in next empty Row in another Sheet

xs4amit

New Member
Joined
May 21, 2018
Messages
34
Hi,

I am trying to copy multiple (Non Continuous) cells from sheet1 and wants to arrange them in an order (in a single Row) and paste them in next available Row.
For example:
ABCDE
1
2ABC
3DEFXYZ
4LEF
5

<tbody>
</tbody>

now i want to paste them in next sheet like:

ABCDE
1ABCDEFXYZLEF
2
3
4
5

<tbody>
</tbody>

And next time i need that the values should go to the next available empty Row automatically. Any idea how to do that??
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Does the consolidation run by rows or columns? In other words, if you initially had:

Rich (BB code):
	A	B	C	D	E
1					
2		ABC			XYZ
3		DEF			LEF
4					
5			

would it go same as you said, or instead like this:

Rich (BB code):
	A	B	C	D	E
1	ABC	XYZ	DEF	LEF	
2


Also, what do you mean exactly by "next time"? How are the cells populated? What triggers the new arrangement?
 
Last edited:
Upvote 0
Does the consolidation run by rows or columns? In other words, if you initially had:

Rich (BB code):
    A    B    C    D    E
1                    
2        ABC            XYZ
3        DEF            LEF
4                    
5            

would it go same as you said, or instead like this:

Rich (BB code):
    A    B    C    D    E
1    ABC    XYZ    DEF    LEF    
2


Also, what do you mean exactly by "next time"? How are the cells populated? What triggers the new arrangement?

Hi Iliace,

thanks for showing interest. The consolidation will go the same as i said. Next time new values will populate exactly in the same cells.
 
Upvote 0
Can you try this and reply with feedback? Run this with your sheet activated, as in the example you showed above.

Code:
Public Sub AutoArrange()
  Dim rngArea As Excel.Range
  Dim rngNext As Excel.Range
  
  Dim rng As Excel.Range
  
  Dim i As Long, j As Long
  
  Set rngArea = ActiveSheet.UsedRange
  
  Set rngNext = ActiveSheet.Range("A1")
  
  If Len(rngNext.Value) > 0 Then
    With rngNext.EntireRow
      Set rngNext = .Cells(1, .Columns.Count).End(xlToLeft).Offset(0, 1)
    End With
    With rngArea
      Set rngArea = .Offset(1, 0).Resize(rowsize:=.Rows.Count - 1)
    End With
  End If
  
  For j = 1 To rngArea.Columns.Count
    For i = 1 To rngArea.Rows.Count
      Set rng = rngArea.Cells(i, j)
      If Len(rng.Value) > 0 Then
        rng.Copy rngNext
        rng.Clear
        Set rngNext = rngNext.Offset(0, 1)
      End If
    Next i
  Next j

End Sub
 
Last edited:
Upvote 0
Can you try this and reply with feedback? Run this with your sheet activated, as in the example you showed above.

Code:
Public Sub AutoArrange()
  Dim rngArea As Excel.Range
  Dim rngNext As Excel.Range
  
  Dim rng As Excel.Range
  
  Dim i As Long, j As Long
  
  Set rngArea = ActiveSheet.UsedRange
  
  Set rngNext = ActiveSheet.Range("A1")
  
  If Len(rngNext.Value) > 0 Then
    With rngNext.EntireRow
      Set rngNext = .Cells(1, .Columns.Count).End(xlToLeft).Offset(0, 1)
    End With
    With rngArea
      Set rngArea = .Offset(1, 0).Resize(rowsize:=.Rows.Count - 1)
    End With
  End If
  
  For j = 1 To rngArea.Columns.Count
    For i = 1 To rngArea.Rows.Count
      Set rng = rngArea.Cells(i, j)
      If Len(rng.Value) > 0 Then
        rng.Copy rngNext
        rng.Clear
        Set rngNext = rngNext.Offset(0, 1)
      End If
    Next i
  Next j

End Sub

Hi Iliace,

Your code is fantastic. But it is not what i was in need of (but i learned how to arrange cells in order). I will elaborate my needs a little more:

1. First thing, there are few more cells which need to be arranged and rest of the cells are not empty, they also have data. So the table which need to be arranged will be like:

NameAmitDate23/May/2018Meeting StatusScheduled
Emp IDA1620Time12:00:00Meeting Time14:00:00
Meeting IDMeeting Password
567493*12345*

<tbody>
</tbody>


2. Once all the details are filled, this should go to next sheet "Sheet2" and search for next available empty Row and arrange it like:

NameEmp IDDateTimeMeeting StatusMeeting TimeMeeting IDMeeting Password
iliaceA159322/May/201811:00:00Completed12:00:00543728*34567*
AmitA162023/May/201812:00:00Scheduled14:00:00567493*12345*

<tbody>
</tbody>


Hope this helps to understand it better. Thanks a lot for your valuable time and help.
 
Upvote 0
Hi Amit - thank you for clarifying.

Let me make sure I am understanding correctly.

Are the headers always consistent? In other words, Name, Emp ID, Date, etc - those will always appear on the source sheet? Matching what it says on Sheet2?

Now, on the source sheet, you will have a header, and then the corresponding piece of data, in an adjacent cell, either below or to the right?

In that case, what do you do when there is ambiguity; for example:

Time12:00:00
NameAmit

How do you propose, in this instance, to determine whether Time is "12:00:00" or "Amit"?
 
Upvote 0

Forum statistics

Threads
1,214,632
Messages
6,120,655
Members
448,975
Latest member
sweeberry

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