K
Ken
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
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