I have a macro that was written in Office 2003, since we upgraded to Office 2010 (I know, it's taken us a while...) the macro will run but not complete the print function which means that we have to manually filter the records to print. Can anyone tell me where the issue is?
thanks
Sub Manifest() On Error GoTo ERROR_PRINT_MANIFEST Dim selDate As Date selDate = InputBox("Enter date to print", "Manifest Print", Trim(Left(Now, 10))) Dim branchRange As String branchRange = Strings.Trim(InputBox("Enter range of branch list", "Manifest Print", Sheets("Data Entry").Cells(2, 9))) Dim firstCell As String Dim lastCell As String firstCell = Strings.Left(branchRange, Strings.InStr(1, branchRange, ":", vbTextCompare) - 1) lastCell = Strings.Right(branchRange, Strings.Len(branchRange) - Strings.InStr(1, branchRange, ":", vbTextCompare)) Dim firstRow As Integer Dim lastRow As Integer firstRow = Range(firstCell).Row lastRow = Range(lastCell).Row Dim col As Integer col = Range(firstCell).Column Dim bottomRow As Integer Range("B2").Select If (IsEmpty(ActiveCell)) Then GoTo EXIT_PRINT_MANIFEST Else Range("B1").Select Selection.End(xlDown).Select bottomRow = ActiveCell.Row End If Range("A1:g65536").Select Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Key2:=Range("C2") _ , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _ False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _ :=xlSortNormal Dim lineNoRow As Integer Dim tempRow As Integer Dim prev1 As Date Dim prev2 As String Dim curr1 As Date Dim curr2 As String prev1 = Empty prev2 = Empty curr1 = Empty curr2 = Empty For lineNoRow = 2 To bottomRow curr1 = Cells(lineNoRow, 2) curr2 = Cells(lineNoRow, 3) If prev1 <> curr1 Then tempRow = 1 Cells(lineNoRow, 1) = tempRow tempRow = tempRow + 1 Else If prev2 <> curr2 Then tempRow = 1 Cells(lineNoRow, 1) = tempRow tempRow = tempRow + 1 Else Cells(lineNoRow, 1) = tempRow tempRow = tempRow + 1 End If End If prev1 = curr1 prev2 = curr2 Next Range("A1:g65536").Select Selection.AutoFilter Field:=2, Criteria1:=selDate Dim currBranch As Integer For currBranch = firstRow To lastRow Selection.AutoFilter Field:=3, Criteria1:=Cells(currBranch, col) ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True Next Range("A1").Select Selection.AutoFilter MsgBox "Successful." GoTo EXIT_PRINT_MANIFEST ERROR_PRINT_MANIFEST: MsgBox "Exiting..." EXIT_PRINT_MANIFEST: End Sub
Last edited by dperry; 02-14-2012 at 02:31 PM.
One difference in 2010 is the amount of rows and columns. Possibly changing your Integers to Long...?
thanks, I've tried changing the integers to long, what seems to be happening now is that it goes through the process but the filter on the branch doesn't work, what prints out is blank paper with just the preset headers, none of the information is captured in the filter. I have attached a copy of the file in case it's easier to see the issue by looking at it.
thanksOutwards despatch office 2010 test.xls
Can you tell me what an input would be for branchRange?
The range would be i4:i26
Try this...
Sub Manifest() Dim selDate As Date Dim branchRange As Range Dim currBranch As Range On Error GoTo ERROR_PRINT_MANIFEST If IsEmpty(Range("B2")) Then GoTo EXIT_PRINT_MANIFEST selDate = InputBox("Enter date to print", "Manifest Print", Trim(Left(Date, 10))) Set branchRange = Application.InputBox("Select a range of branch list", "Manifest Print", Type:=8) With Range("A1").CurrentRegion .Sort Key1:=Range("B2"), Order1:=xlAscending, Key2:=Range("C2"), _ Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _ Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal .AutoFilter Field:=2, Operator:=xlFilterValues, Criteria1:="=" & selDate For Each currBranch In branchRange .AutoFilter Field:=3, Operator:=xlFilterValues, Criteria1:=CStr(currBranch.Value) .PrintOut Next currBranch .AutoFilter End With MsgBox "Successful." GoTo EXIT_PRINT_MANIFEST ERROR_PRINT_MANIFEST: MsgBox "Exiting..." EXIT_PRINT_MANIFEST: End Sub
Thanks, this works well and everything printed out ok. The only thing now is that it doesn't add a line iten number next to the line item for each branch after sorting it anymore, (3 lines on a branch would be numbered 1,2 & 3 respectively in the left column) I'm not sure how to add that back in from the original code.
thanks
In your original code, change this line:
to this:Selection.AutoFilter Field:=2, Criteria1:=selDate
Selection.AutoFilter Field:=2, Criteria1:="=" & selDate
Awesome, this works a treat now. Many thanks for your help
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks