I am new to Macros. I have made a macro that I would like some help with. The last function does not work properly. I need it keep just the rows that contain "xx Total" in column "R".
Code:
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 3/10/2009 by bmay
'
'
Application.ScreenUpdating = False
Windows("macro book.xls").Activate
Rows("23:43").Select
Selection.Copy
Windows("Run.xls").Activate
Rows("2:2").Select
Selection.Insert Shift:=xlDown
Range("BD1").Select
ActiveCell.FormulaR1C1 = "order"
Range("BD2").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-38],'[macro book.xls]Sheet1'!R1C1:R30C2,2,FALSE)"
If IsEmpty(ActiveCell) Then Exit Sub
Range(ActiveCell, ActiveCell.Offset(0, -1).End(xlDown).Offset(0, 1)).FillDown
Range("BD:BD").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Cells.Select
Range("AP1").Activate
Selection.Sort Key1:=Range("BD2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Selection.Subtotal GroupBy:=18, Function:=xlSum, TotalList:=Array(55), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
Range("AP1").Activate
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Selection.CurrentRegion.Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Columns("BC:BC").Select
Selection.NumberFormat = "0.00"
Sheets("Run").Copy After:=Sheets(1)
Sheets("Run (2)").Name = "data"
Dim LR As Long, i As Long
With Sheets("data")
LR = .Range("R" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
If Not .Range("O" & i).Value Like "*Total*" Then .Rows(i).Delete
Next i
End With
Application.ScreenUpdating = True
End Sub
Code:
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 3/10/2009 by bmay
'
'
Application.ScreenUpdating = False
Windows("macro book.xls").Activate
Rows("23:43").Select
Selection.Copy
Windows("Run.xls").Activate
Rows("2:2").Select
Selection.Insert Shift:=xlDown
Range("BD1").Select
ActiveCell.FormulaR1C1 = "order"
Range("BD2").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-38],'[macro book.xls]Sheet1'!R1C1:R30C2,2,FALSE)"
If IsEmpty(ActiveCell) Then Exit Sub
Range(ActiveCell, ActiveCell.Offset(0, -1).End(xlDown).Offset(0, 1)).FillDown
Range("BD:BD").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Cells.Select
Range("AP1").Activate
Selection.Sort Key1:=Range("BD2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Selection.Subtotal GroupBy:=18, Function:=xlSum, TotalList:=Array(55), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
Range("AP1").Activate
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Selection.CurrentRegion.Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Columns("BC:BC").Select
Selection.NumberFormat = "0.00"
Sheets("Run").Copy After:=Sheets(1)
Sheets("Run (2)").Name = "data"
Dim LR As Long, i As Long
With Sheets("data")
LR = .Range("R" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
If Not .Range("O" & i).Value Like "*Total*" Then .Rows(i).Delete
Next i
End With
Application.ScreenUpdating = True
End Sub