+ Reply to Thread
Results 1 to 9 of 9

Thread: Macro not working in Office 2010

  1. #1
    Registered User
    Join Date
    04-13-2009
    Location
    Auckland, New Zealand
    MS-Off Ver
    2010
    Posts
    41

    Macro not working in Office 2010

    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.

  2. #2
    Valued Forum Contributor
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    380

    Re: Macro not working in Office 2010

    One difference in 2010 is the amount of rows and columns. Possibly changing your Integers to Long...?

  3. #3
    Registered User
    Join Date
    04-13-2009
    Location
    Auckland, New Zealand
    MS-Off Ver
    2010
    Posts
    41

    Re: Macro not working in Office 2010

    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

  4. #4
    Valued Forum Contributor
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    380

    Re: Macro not working in Office 2010

    Can you tell me what an input would be for branchRange?

  5. #5
    Registered User
    Join Date
    04-13-2009
    Location
    Auckland, New Zealand
    MS-Off Ver
    2010
    Posts
    41

    Re: Macro not working in Office 2010

    The range would be i4:i26

  6. #6
    Valued Forum Contributor
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    380

    Re: Macro not working in Office 2010

    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

  7. #7
    Registered User
    Join Date
    04-13-2009
    Location
    Auckland, New Zealand
    MS-Off Ver
    2010
    Posts
    41

    Re: Macro not working in Office 2010

    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

  8. #8
    Valued Forum Contributor
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    380

    Re: Macro not working in Office 2010

    In your original code, change this line:
        Selection.AutoFilter Field:=2, Criteria1:=selDate
    to this:
        Selection.AutoFilter Field:=2, Criteria1:="=" & selDate

  9. #9
    Registered User
    Join Date
    04-13-2009
    Location
    Auckland, New Zealand
    MS-Off Ver
    2010
    Posts
    41

    Talking Re: Macro not working in Office 2010

    Awesome, this works a treat now. Many thanks for your help

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0