+ Reply to Thread
Results 1 to 5 of 5

Macro to copy a row, then insert shift:=x1Down

  1. #1
    Lost in Alabama
    Guest

    Macro to copy a row, then insert shift:=x1Down

    I am trying to create a macro to scan the data in Column H, when a "1" is
    found, move one row up, copy that row and insert the copied row of data. I
    have tried the following code, but it does not work and I cannot find an
    answer in the searches I have done.

    I would greatly appreciate help!

    For Each Cell In Range("H:H")
    If Cell.Value = "1" Then
    Cell.Offset(-1, 0).Rows("1:1").EntireRow.Select
    Selection.Copy.Insert Shift:=x1Down
    End If
    Next Cell

    Lost in Alabama


  2. #2
    Tom Ogilvy
    Guest

    RE: Macro to copy a row, then insert shift:=x1Down

    LastRow = cells(rows.count,"H").End(xlup).Row
    for i = lastrow to 1 step -1
    If Cells(i + 1,1) = "1" Then
    Rows(i).Copy
    Rows(i + 1).Insert
    End If
    Next i

    --
    Regards,
    Tom Ogilvy


    "Lost in Alabama" wrote:

    > I am trying to create a macro to scan the data in Column H, when a "1" is
    > found, move one row up, copy that row and insert the copied row of data. I
    > have tried the following code, but it does not work and I cannot find an
    > answer in the searches I have done.
    >
    > I would greatly appreciate help!
    >
    > For Each Cell In Range("H:H")
    > If Cell.Value = "1" Then
    > Cell.Offset(-1, 0).Rows("1:1").EntireRow.Select
    > Selection.Copy.Insert Shift:=x1Down
    > End If
    > Next Cell
    >
    > Lost in Alabama
    >


  3. #3
    Lost in Alabama
    Guest

    RE: Macro to copy a row, then insert shift:=x1Down

    Thank you, Tom, for the quick response. I tried this code, but it does not
    change my data at all. Any suggestions?

    Thanks,

    Lost

    "Tom Ogilvy" wrote:

    > LastRow = cells(rows.count,"H").End(xlup).Row
    > for i = lastrow to 1 step -1
    > If Cells(i + 1,1) = "1" Then
    > Rows(i).Copy
    > Rows(i + 1).Insert
    > End If
    > Next i
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Lost in Alabama" wrote:
    >
    > > I am trying to create a macro to scan the data in Column H, when a "1" is
    > > found, move one row up, copy that row and insert the copied row of data. I
    > > have tried the following code, but it does not work and I cannot find an
    > > answer in the searches I have done.
    > >
    > > I would greatly appreciate help!
    > >
    > > For Each Cell In Range("H:H")
    > > If Cell.Value = "1" Then
    > > Cell.Offset(-1, 0).Rows("1:1").EntireRow.Select
    > > Selection.Copy.Insert Shift:=x1Down
    > > End If
    > > Next Cell
    > >
    > > Lost in Alabama
    > >


  4. #4
    Tom Ogilvy
    Guest

    Re: Macro to copy a row, then insert shift:=x1Down

    Reworked the macro at the last minute and forgot to change a column
    Reference from 1 to "H"
    made the correction

    LastRow = cells(rows.count,"H").End(xlup).Row
    for i = lastrow to 1 step -1
    If Cells(i + 1,"H") = "1" Then
    Rows(i).Copy
    Rows(i + 1).Insert
    End If
    Next i

    --
    Regards,
    Tom Ogilvy



    "Lost in Alabama" <[email protected]> wrote in message
    news:[email protected]...
    > Thank you, Tom, for the quick response. I tried this code, but it does

    not
    > change my data at all. Any suggestions?
    >
    > Thanks,
    >
    > Lost
    >
    > "Tom Ogilvy" wrote:
    >
    > > LastRow = cells(rows.count,"H").End(xlup).Row
    > > for i = lastrow to 1 step -1
    > > If Cells(i + 1,1) = "1" Then
    > > Rows(i).Copy
    > > Rows(i + 1).Insert
    > > End If
    > > Next i
    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > >
    > > "Lost in Alabama" wrote:
    > >
    > > > I am trying to create a macro to scan the data in Column H, when a "1"

    is
    > > > found, move one row up, copy that row and insert the copied row of

    data. I
    > > > have tried the following code, but it does not work and I cannot find

    an
    > > > answer in the searches I have done.
    > > >
    > > > I would greatly appreciate help!
    > > >
    > > > For Each Cell In Range("H:H")
    > > > If Cell.Value = "1" Then
    > > > Cell.Offset(-1, 0).Rows("1:1").EntireRow.Select
    > > > Selection.Copy.Insert Shift:=x1Down
    > > > End If
    > > > Next Cell
    > > >
    > > > Lost in Alabama
    > > >




  5. #5
    Lost in Alabama
    Guest

    Re: Macro to copy a row, then insert shift:=x1Down

    Tom,

    You are a Blessing! This works perfectly....not sure I unnderstand it all,
    but it works great!

    Thanks again for sharing your knowledge.

    Lost

    "Tom Ogilvy" wrote:

    > Reworked the macro at the last minute and forgot to change a column
    > Reference from 1 to "H"
    > made the correction
    >
    > LastRow = cells(rows.count,"H").End(xlup).Row
    > for i = lastrow to 1 step -1
    > If Cells(i + 1,"H") = "1" Then
    > Rows(i).Copy
    > Rows(i + 1).Insert
    > End If
    > Next i
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    >
    > "Lost in Alabama" <[email protected]> wrote in message
    > news:[email protected]...
    > > Thank you, Tom, for the quick response. I tried this code, but it does

    > not
    > > change my data at all. Any suggestions?
    > >
    > > Thanks,
    > >
    > > Lost
    > >
    > > "Tom Ogilvy" wrote:
    > >
    > > > LastRow = cells(rows.count,"H").End(xlup).Row
    > > > for i = lastrow to 1 step -1
    > > > If Cells(i + 1,1) = "1" Then
    > > > Rows(i).Copy
    > > > Rows(i + 1).Insert
    > > > End If
    > > > Next i
    > > >
    > > > --
    > > > Regards,
    > > > Tom Ogilvy
    > > >
    > > >
    > > > "Lost in Alabama" wrote:
    > > >
    > > > > I am trying to create a macro to scan the data in Column H, when a "1"

    > is
    > > > > found, move one row up, copy that row and insert the copied row of

    > data. I
    > > > > have tried the following code, but it does not work and I cannot find

    > an
    > > > > answer in the searches I have done.
    > > > >
    > > > > I would greatly appreciate help!
    > > > >
    > > > > For Each Cell In Range("H:H")
    > > > > If Cell.Value = "1" Then
    > > > > Cell.Offset(-1, 0).Rows("1:1").EntireRow.Select
    > > > > Selection.Copy.Insert Shift:=x1Down
    > > > > End If
    > > > > Next Cell
    > > > >
    > > > > Lost in Alabama
    > > > >

    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1