Ending a macro?

G

Guest

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
 
M

MattShoreson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top