+ Reply to Thread
Results 1 to 4 of 4

Insert Row macro not working

  1. #1
    Acct Supr - DCTC
    Guest

    Insert Row macro not working

    I have the following macro set up but it keeps hanging up on the first
    indented line.

    Sub Insertrow()
    '
    ' Insertrow Macro
    ' Macro recorded 10/6/2005 by DCTC
    '
    ' Keyboard Shortcut: Ctrl+i
    '
    Dim iLastRow As Long
    Dim i As Long
    iLastRow = ActiveSheet.Cells(Rows.Count, "F").End(x1Up).Row
    For i = iLastRow To 1 Step -1
    If Cells(i, "F").Value = "Total" Then
    Rows(i + 1).EntireRow.Insert
    End If
    Next i
    End Sub

  2. #2
    Don Guillett
    Guest

    Re: Insert Row macro not working

    a cursory look suggests you need to change 1 to l

    --
    Don Guillett
    SalesAid Software
    [email protected]
    "Acct Supr - DCTC" <[email protected]> wrote in message
    news:[email protected]...
    > I have the following macro set up but it keeps hanging up on the first
    > indented line.
    >
    > Sub Insertrow()
    > '
    > ' Insertrow Macro
    > ' Macro recorded 10/6/2005 by DCTC
    > '
    > ' Keyboard Shortcut: Ctrl+i
    > '
    > Dim iLastRow As Long
    > Dim i As Long
    > iLastRow = ActiveSheet.Cells(Rows.Count, "F").End(x1Up).Row
    > For i = iLastRow To 1 Step -1
    > If Cells(i, "F").Value = "Total" Then
    > Rows(i + 1).EntireRow.Insert
    > End If
    > Next i
    > End Sub




  3. #3
    Chris Lavender
    Guest

    Re: Insert Row macro not working

    Try using

    iLastRow = Range("F1").End(xlDown).Row

    rather than

    iLastRow = ActiveSheet.Cells(Rows.Count, "F").End(x1Up).Row

    Best rgds
    Chris Lav


    "Don Guillett" <[email protected]> wrote in message
    news:[email protected]...
    > a cursory look suggests you need to change 1 to l
    >
    > --
    > Don Guillett
    > SalesAid Software
    > [email protected]
    > "Acct Supr - DCTC" <[email protected]> wrote in

    message
    > news:[email protected]...
    > > I have the following macro set up but it keeps hanging up on the first
    > > indented line.
    > >
    > > Sub Insertrow()
    > > '
    > > ' Insertrow Macro
    > > ' Macro recorded 10/6/2005 by DCTC
    > > '
    > > ' Keyboard Shortcut: Ctrl+i
    > > '
    > > Dim iLastRow As Long
    > > Dim i As Long
    > > iLastRow = ActiveSheet.Cells(Rows.Count, "F").End(x1Up).Row
    > > For i = iLastRow To 1 Step -1
    > > If Cells(i, "F").Value = "Total" Then
    > > Rows(i + 1).EntireRow.Insert
    > > End If
    > > Next i
    > > End Sub

    >
    >




  4. #4
    David McRitchie
    Guest

    Re: Insert Row macro not working

    Hi Chris,
    The poster is much better off correcting the original as Don indicated
    but the poster might still not see right away that it was an x1 prefix
    incorrectly used as an xl prefix to a builtin constant. Took me a while
    to get that right when seeing posted solutions and help files.

    The reason the orginal is better is because it starts from the
    bottom of the column and looks for the first nonempty cell to
    find your last used in the column.

    The reason the second one is bad is because it starts from
    the top and finds the first empty cell -- you could easily have
    an empty cell in a column including from having an empty row
    to separate data or to provide for filling in data later.

    Of possible interest
    http://www.mvps.org/dmcritchie/excel/insrtrow.htm
    ---
    HTH,
    David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
    My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
    Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

    "Chris Lavender" <[email protected]> wrote in message news:[email protected]...
    > Try using
    >
    > iLastRow = Range("F1").End(xlDown).Row
    >
    > rather than
    >
    > iLastRow = ActiveSheet.Cells(Rows.Count, "F").End(x1Up).Row
    >
    > Best rgds
    > Chris Lav
    >
    >
    > "Don Guillett" <[email protected]> wrote in message
    > news:[email protected]...
    > > a cursory look suggests you need to change 1 to l
    > >
    > > --
    > > Don Guillett
    > > SalesAid Software
    > > [email protected]
    > > "Acct Supr - DCTC" <[email protected]> wrote in

    > message
    > > news:[email protected]...
    > > > I have the following macro set up but it keeps hanging up on the first
    > > > indented line.
    > > >
    > > > Sub Insertrow()
    > > > '
    > > > ' Insertrow Macro
    > > > ' Macro recorded 10/6/2005 by DCTC
    > > > '
    > > > ' Keyboard Shortcut: Ctrl+i
    > > > '
    > > > Dim iLastRow As Long
    > > > Dim i As Long
    > > > iLastRow = ActiveSheet.Cells(Rows.Count, "F").End(x1Up).Row
    > > > For i = iLastRow To 1 Step -1
    > > > If Cells(i, "F").Value = "Total" Then
    > > > Rows(i + 1).EntireRow.Insert
    > > > End If
    > > > Next i
    > > > End Sub

    > >
    > >

    >
    >




+ 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