trying to debug macro to copy and insert lines when cell is not empty

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
 

Some videos you may like

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,578
Office Version
  1. 365
Platform
  1. Windows
Hello & welcome
What exactly is not working?
This looks to do what your asking for.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,429
Messages
5,528,705
Members
409,830
Latest member
KT50

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top