unaragazza
New Member
- Joined
- Sep 18, 2014
- Messages
- 1
Hi, I'm trying to write a fairly simple macro and would appreciate any help debugging it.
The macro is intended to look at a row of text, and check and see if column E is empty. If it is empty, proceed to the next row and repeat. If it is not empty, the macro should insert a new line underneath, cut the data from columns E,F, and G in that row, and paste into column B in the newly created row beneath. Then it should copy the unique ID from column A above into the new row. It should then proceed to the next row and repeat through 50 rows. Here's what I have so far, but it's not working. Thanks!
Sub line_moving()
'
' line_moving Macro
ActiveCell.Offset(0, 4).Select
For i = 1 To 50
If Cells(i, 5) <> "" Then
ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select
Selection.Insert Shift:=xlDown
ActiveCell.Offset(-1, 4).Range("A1:C1").Select
Selection.Cut
ActiveCell.Offset(1, -3).Range("A1").Select
ActiveSheet.Paste
ActiveCell.Offset(-1, -1).Range("A1").Select
Selection.Copy
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
Else
ActiveCell.Offset(1, 0).Select
End If
Next i
End Sub
The macro is intended to look at a row of text, and check and see if column E is empty. If it is empty, proceed to the next row and repeat. If it is not empty, the macro should insert a new line underneath, cut the data from columns E,F, and G in that row, and paste into column B in the newly created row beneath. Then it should copy the unique ID from column A above into the new row. It should then proceed to the next row and repeat through 50 rows. Here's what I have so far, but it's not working. Thanks!
Sub line_moving()
'
' line_moving Macro
ActiveCell.Offset(0, 4).Select
For i = 1 To 50
If Cells(i, 5) <> "" Then
ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select
Selection.Insert Shift:=xlDown
ActiveCell.Offset(-1, 4).Range("A1:C1").Select
Selection.Cut
ActiveCell.Offset(1, -3).Range("A1").Select
ActiveSheet.Paste
ActiveCell.Offset(-1, -1).Range("A1").Select
Selection.Copy
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
Else
ActiveCell.Offset(1, 0).Select
End If
Next i
End Sub