I did change it, now its crashing my excel sheet.
It keeps coming up with the error message, over and over again even after I click OK on it.
Any ideas?
Thanks Greg
Here is the code:
Sub Macro3()
'
' Macro3 Macro
'
' Keyboard Shortcut: Ctrl+Shift+T
'
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Sheets("data").Select
Range("A2").Select
Cells.Replace What:="BULKMATIC TRANSPORT COMPANY", Replacement:= _
"CONAGRA", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Dim cell As Range
Dim rng As Range
On Error GoTo 100
Worksheets("data").Activate
Set rng = Range("D2:D5000")
For Each cell In rng
If cell.Value = "" Then GoTo 100
Select Case cell.Value
Case "CARGILL INC"
Range("A" & cell.Row, "AK" & cell.Row).Copy
Sheets("Cargill").Range("A65000").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = True
End Select
Next cell
ActiveWorkbook.Worksheets("data").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("data").Sort.SortFields.Add Key:= _
Range("A:AK"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
ActiveWorkbook.Worksheets("data").Sort.SortFields.Add Key:= _
Range("D:D"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
100
Sheets("rated").Select
Range("C4").Select
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
Sheets("billing").Select
Range("B4").Select
ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh
Sheets("Cargill").Select
Cells.Select
Range("B2").Activate
ActiveWorkbook.Worksheets("Cargill").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Cargill").Sort.SortFields.Add Key:=Range("M2:M5000" _
), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Cargill").Sort
.SetRange Range("A1:AK5000")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("Cargill").Select
Columns("N:N").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("N:N").Select
Selection.Style = "Currency"
Range("N2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-1]=R[-1]C[-1],0,728)"
Selection.AutoFill Destination:=Range("N2:N5000"), Type:=xlFillDefault
Selection.AutoFill Destination:=Range("N2:N5000"), Type:=xlFillDefault
Range("N2:N5000").Select
Range("N1").Select
ActiveCell.FormulaR1C1 = "Vehicle Charge"
With ActiveCell.Characters(Start:=1, Length:=14).Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Selection.Subtotal GroupBy:=4, Function:=xlSum, TotalList:=Array(14), _
Replace:=True, PageBreaks:=True, SummaryBelowData:=True
Selection.AutoFilter
ActiveSheet.Range("$A$1:$AL$5001").AutoFilter Field:=4, Criteria1:="<>"
Range("N5002").Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[-5000]C:R[-1]C)/728"
Range("N5002").Select
Selection.NumberFormat = "General"
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns("B:D").EntireColumn.AutoFit
Columns("G:H").EntireColumn.AutoFit
Columns("D:D").EntireColumn.AutoFit
Columns("M:T").EntireColumn.AutoFit
Columns("AD:AI").EntireColumn.AutoFit
Application.DisplayAlerts = True
Dim wsPT As Worksheet
On Error GoTo Handler:
Set wsPT = Sheets("billing")
wsPT.Cells(Application.Match("Grand Total", wsPT.Columns(1), 0), "C").ShowDetail = True
ExitPoint:
Set wsPT = Nothing
Handler:
MsgBox "Error Has Occurred etc...", vbCritical, "Routine Terminated"
Resume ExitPoint
Exit Sub
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.DisplayAlerts = False
End Sub
Bookmarks