+ Reply to Thread
Results 1 to 3 of 3

Ending a macro?

  1. #1
    Paul
    Guest

    Ending a macro?

    I've got the following code working fine as a result of some wonderful
    feedack from members., I just run the macro until it runs
    out of data to find. The only problem is that when there is no more data to
    find, the macro ends as an error. Is there any way of ending the macro
    "cleanly"when there are no more entries?

    Thanks again for the help.

    Paul
    Sub Pastedetails()

    ' Cutpaste Macro
    ' Macro recorded 22/11/2005 by IT Services
    '
    ' Keyboard Shortcut: Ctrl+x

    Sheets("Posting").Activate

    x = Columns(3).Find("Reconciliations - Outstanding Items").Row
    y = Columns(3).Find("Account Balance - Per master File").Row
    z = Sheets("Posting").Cells(Rows.Count, "a").End(xlUp).Row + 1
    Rows(x & ":" & y).Cut

    Sheets("Summary").Activate
    ActiveCell.SpecialCells (xlCellTypeLastCell)

    ActiveSheet.Paste

    Cells.Select
    Cells.EntireColumn.AutoFit

    Windows("Suspense1.xls").Activate
    ActiveCell.SpecialCells(xlCellTypeLastCell).Offset(1, -5).Select

    End Sub


  2. #2
    Forum Contributor
    Join Date
    12-04-2003
    Posts
    360
    A quick way of doing it - is to do the following

    Sub Pastedetails()

    ' Cutpaste Macro
    ' Macro recorded 22/11/2005 by IT Services
    '
    ' Keyboard Shortcut: Ctrl+x

    on error goto err_handler

    Sheets("Posting").Activate

    x = Columns(3).Find("Reconciliations - Outstanding Items").Row
    y = Columns(3).Find("Account Balance - Per master File").Row
    z = Sheets("Posting").Cells(Rows.Count, "a").End(xlUp).Row + 1
    Rows(x & ":" & y).Cut

    Sheets("Summary").Activate
    ActiveCell.SpecialCells (xlCellTypeLastCell)

    ActiveSheet.Paste

    Cells.Select
    Cells.EntireColumn.AutoFit

    Windows("Suspense1.xls").Activate
    ActiveCell.SpecialCells(xlCellTypeLastCell).Offset (1, -5).Select

    exit sub

    err_handler:

    'put any error conditions here.


    End Sub

  3. #3
    Paul
    Guest

    Re: Ending a macro?

    Thanks for that, it's working fine.

    Much appreciated.

    Paul

    "MattShoreson" wrote:

    >
    > A quick way of doing it - is to do the following
    >
    > Sub Pastedetails()
    >
    > ' Cutpaste Macro
    > ' Macro recorded 22/11/2005 by IT Services
    > '
    > ' Keyboard Shortcut: Ctrl+x
    >
    > on error goto err_handler
    >
    > Sheets("Posting").Activate
    >
    > x = Columns(3).Find("Reconciliations - Outstanding Items").Row
    > y = Columns(3).Find("Account Balance - Per master File").Row
    > z = Sheets("Posting").Cells(Rows.Count, "a").End(xlUp).Row + 1
    > Rows(x & ":" & y).Cut
    >
    > Sheets("Summary").Activate
    > ActiveCell.SpecialCells (xlCellTypeLastCell)
    >
    > ActiveSheet.Paste
    >
    > Cells.Select
    > Cells.EntireColumn.AutoFit
    >
    > Windows("Suspense1.xls").Activate
    > ActiveCell.SpecialCells(xlCellTypeLastCell).Offset (1, -5).Select
    >
    > exit sub
    >
    > err_handler:
    >
    > 'put any error conditions here.
    >
    >
    > End Sub
    >
    >
    > --
    > MattShoreson
    > ------------------------------------------------------------------------
    > MattShoreson's Profile: http://www.excelforum.com/member.php...fo&userid=3472
    > View this thread: http://www.excelforum.com/showthread...hreadid=489129
    >
    >


+ 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