LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default On Error Help

We have a macro which we begin by turning off manual
recalculation, screen updating, etc. Then we import a text
file and run some code. At the end we turn the manual
recalculation, screen updating, etc. back on.

If the text file is not found or if the macro somehow
bombs, I want to have an error trapping routine that will
give the user an error message and that will also re-set
the manual recalculation. What code would I use to do this?

TIA.

Sub Test()

Dim CountRows As Double
Dim I As Double
Dim Fund As String
Dim BFYS As String

'Turn off warnings, auto recalc, etc.
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False

ChDir "C:\Downloads"

Workbooks.OpenText Filename:="C:\Downloads\F851.txt",
Origin:=xlWindows, _
StartRow:=4, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, 2), Array(15 _
, 2), Array(25, 2), Array(37, 2), Array(53, 3),
Array(65, 1), Array(71, 1), Array(91, 1), _
Array(111, 1))

CountRows = Range("A65536").End(xlUp).Row

For I = 1 To CountRows
If Left(ActiveCell, 2) = "AR" Or Left(ActiveCell,
2) = "RC" Or Left(ActiveCell, 2) = "RT" Then
ActiveCell.Offset(1, 0).Select
Else
If Left(ActiveCell, 3) < "STN" Then
ActiveCell.EntireRow.Select
Selection.Delete Shift:=xlUp
Else
If BFYS < ActiveCell.Offset(0,
3).Value Or Fund < ActiveCell.Offset(0, 4).Value Then
BFYS = ActiveCell.Offset(0,
3).Value
Fund = ActiveCell.Offset(0,
4).Value
Selection.Clear
ActiveCell = BFYS
ActiveCell.Font.Bold = True
ActiveCell.Offset(0, 1) = Fund
ActiveCell.Offset(0, 1).Font.Bold
= True
ActiveCell.Offset(1, 0).Select

Else
ActiveCell.EntireRow.Select
Selection.Delete Shift:=xlUp
End If
End If
End If
Next I

Range("A1").Select

'Turn on warnings, auto recalc, etc.
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 - error saving file & error loading dll TinaF Excel Discussion (Misc queries) 0 July 1st 09 01:49 PM
Error of slope taking into account error of the data points cer144 Excel Worksheet Functions 5 July 7th 08 07:26 PM
Counting instances of found text (Excel error? Or user error?) S Davis Excel Worksheet Functions 5 September 12th 06 04:52 PM
Syntax Error Runtime Error '424' Object Required sjenks183 Excel Programming 1 January 23rd 04 09:25 AM


All times are GMT +1. The time now is 08:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"