View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
tahrah tahrah is offline
external usenet poster
 
Posts: 30
Default Trying to delete rows and it's not working

Martin, Thanks. It calculated for a looooooooong time and ended up
deleting ALL rows. Then it added the column titles, then it hung up
and got stuck on the print area section. Here's the macro with the new
code you provided. Did I do something wrong?

Sub Backlog_By_Product_Number()

Columns("B:B").Select
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft
Columns("D:D").Select
Selection.Delete Shift:=xlToLeft
Columns("E:E").Select
Selection.Delete Shift:=xlToLeft

Dim lngRow As Long, lngLastRow As Long
Dim bRowDelete As Boolean
With ActiveSheet.UsedRange
lngLastRow = .Row + .Rows.Count + 1
End With
Rows(lngRow + 1 & ":" & Cells.Rows.Count).Delete ' clear to end


For lngRow = lngLastRow To 1 Step -1 ' work backwards
bRowDelete = False ' flag for deleting
' check the values
If Trim(Cells(lngRow, 1).Value) = "" Then
bRowDelete = True
ElseIf Trim(UCase(Cells(lngRow, 1).Value)) = "SO NUMBER" Then
bRowDelete = True
ElseIf Trim(Cells(lngRow, 2).Value) = "---" Then
bRowDelete = True
ElseIf Trim(Cells(lngRow, 3).Value) = "" Then
bRowDelete = True
ElseIf Trim(UCase(Cells(lngRow, 3).Value)) = "LOG DETAIL" Then
bRowDelete = True
End If
If bRowDelete = True Then Rows(lngRow).Delete
Next lngRow

Rows("1:2001").Sort Key1:=Range("C1"), Order1:=xlAscending,
Key2:=Range("D1"), Order2:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Range("A1").Select
ActiveCell.FormulaR1C1 = "S.O. NO."
Range("B1").Select
ActiveCell.FormulaR1C1 = "LINE #"
Range("C1").Select
ActiveCell.FormulaR1C1 = "P/N"
Range("D1").Select
ActiveCell.FormulaR1C1 = "DUE DATE"
Range("E1").Select
ActiveCell.FormulaR1C1 = "QTY"
Range("F1").Select
ActiveCell.FormulaR1C1 = "UNIT PRICE"
Range("G1").Select
ActiveCell.FormulaR1C1 = "TOTAL"
Columns("F:G").Select
Selection.NumberFormat = "$#,##0.00"
Rows("1:1").Select
Selection.Font.bold = True
ActiveSheet.PageSetup.PrintArea = Rows("1:" & lngRow - 1).Address
'?
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
.LeftHeader = "PAGE NO. &P"
.CenterHeader = "BACKLOG Sorted By Product Number"
.RightHeader = "&D, &T"
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.75)
.RightMargin = Application.InchesToPoints(0.75)
.TopMargin = Application.InchesToPoints(1)
.BottomMargin = Application.InchesToPoints(1)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlPortrait
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 15
.PrintErrors = xlPrintErrorsDisplayed
End With
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Rows("2:2002").Select
Selection.Sort Key1:=Range("C2"), Order1:=xlAscending,
Key2:=Range("A2") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1,
MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
Range("A2").Select
End Sub