Add empty rows and move data

FredrikNilsen

New Member
Joined
Jan 25, 2021
Messages
26
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
Once a week or so I get an Excel file with data exported from SuperOffice. I need to move some of the data. The number of rows will vary, but the number of columns is always the same. I would like take the data from each cell in column E, and move it to a new empty row below. See illustration. I have found code to add rows, but it would be great if I could do it all in one operation.

Excel.png
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try this
VBA Code:
Sub MoveData()

Application.ScreenUpdating = False
For i = Cells(Rows.Count, "A").End(xlUp).Row To 1 Step -1
    Range("A" & i).Offset(1).EntireRow.Insert
    Range("E" & i).Cut Range("D" & i).Offset(1)
Next
Application.ScreenUpdating = True

End Sub
 
Upvote 0
Solution
Try this
VBA Code:
Sub MoveData()

Application.ScreenUpdating = False
For i = Cells(Rows.Count, "A").End(xlUp).Row To 1 Step -1
    Range("A" & i).Offset(1).EntireRow.Insert
    Range("E" & i).Cut Range("D" & i).Offset(1)
Next
Application.ScreenUpdating = True

End Sub
Perfect, thank you!
 
Upvote 0
Try this
VBA Code:
Sub MoveData()

Application.ScreenUpdating = False
For i = Cells(Rows.Count, "A").End(xlUp).Row To 1 Step -1
    Range("A" & i).Offset(1).EntireRow.Insert
    Range("E" & i).Cut Range("D" & i).Offset(1)
Next
Application.ScreenUpdating = True

End Sub
Is it easy to change this to add the data from column E into the existing data in the corresponding cell in column D, preferably with a linebreak (alt+enter) before?
 
Upvote 0
Is it easy to change this to add the data from column E into the existing data in the corresponding cell in column D, preferably with a linebreak (alt+enter) before?
You meant like this?
VBA Code:
Sub MoveData()

Application.ScreenUpdating = False
For i = Cells(Rows.Count, "A").End(xlUp).Row To 1 Step -1
    Range("A" & i, "D" & i).VerticalAlignment = xlVAlignTop
    Range("D" & i) = Range("D" & i) & vbLf & Range("E" & i).Value
    Range("E" & i).ClearContents
Next
Application.ScreenUpdating = True

End Sub
 
Upvote 0
You meant like this?
VBA Code:
Sub MoveData()

Application.ScreenUpdating = False
For i = Cells(Rows.Count, "A").End(xlUp).Row To 1 Step -1
    Range("A" & i, "D" & i).VerticalAlignment = xlVAlignTop
    Range("D" & i) = Range("D" & i) & vbLf & Range("E" & i).Value
    Range("E" & i).ClearContents
Next
Application.ScreenUpdating = True

End Sub
Amazing! I have to read up on this stuff. Thank you!
 
Upvote 0
Amazing! I have to read up on this stuff. Thank you!
This is just simple step
1) The loop starts from end of row to top so that it will not affect the i row increment
2) Range("A" & i, "D" & i).VerticalAlignment = xlVAlignTop is to align characters to the top (look nicer) since the default is to the bottom if adding Alt+Enter
3) Range("D" & i) = Range("D" & i) & vbLf & Range("E" & i).Value rewrite data in Range("D" & i) with combination of range D and E. The vbLf (VB Linefeed) = Alt+Enter.
4) Range("E" & i).ClearContents is self-explanatory.
 
Upvote 0

Forum statistics

Threads
1,214,798
Messages
6,121,630
Members
449,041
Latest member
Postman24

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