+ Reply to Thread
Results 1 to 6 of 6

Runtime error 91

Hybrid View

MarianneBal Runtime error 91 11-14-2014, 09:10 AM
alansidman Re: Runtime error 91 11-14-2014, 09:12 AM
MarianneBal Re: Runtime error 91 11-14-2014, 09:19 AM
romperstomper Re: Runtime error 91 11-14-2014, 09:43 AM
MarianneBal Re: Runtime error 91 11-14-2014, 10:03 AM
MarianneBal Re: Runtime error 91 11-14-2014, 10:15 AM
  1. #1
    Registered User
    Join Date
    03-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    39

    Runtime error 91

    Hello,

    I just took over a report from someone with some Macros that are not working anymore.

    I get for following code Runtime Error 91 - Object variable or With block variable not set.

    I was reading that I have to SET something, but I'm not sure what for this code below.

    Can anybody help me with that?

      Range("A2").Select
        Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
        Application.CutCopyMode = False
        ActiveWorkbook.Worksheets("Projected Jurisdictional Date U").AutoFilter.Sort. _
            SortFields.Clear
        ActiveWorkbook.Worksheets("Projected Jurisdictional Date U").AutoFilter.Sort. _
            SortFields.Add Key:=Range("Z3:Z33000"), SortOn:=xlSortOnValues, Order:= _
            xlAscending, DataOption:=xlSortNormal
        ActiveWorkbook.Worksheets("Projected Jurisdictional Date U").AutoFilter.Sort. _
            SortFields.Add Key:=Range("K3:K33000"), SortOn:=xlSortOnValues, Order:= _
            xlAscending, DataOption:=xlSortNormal
        ActiveWorkbook.Worksheets("Projected Jurisdictional Date U").AutoFilter.Sort. _
            SortFields.Add Key:=Range("K3:K33000"), SortOn:=xlSortOnValues, Order:= _
            xlAscending, DataOption:=xlSortNormal
        ActiveWorkbook.Worksheets("Projected Jurisdictional Date U").AutoFilter.Sort. _
            SortFields.Add Key:=Range("J3:J33000"), SortOn:=xlSortOnValues, Order:= _
            xlAscending, DataOption:=xlSortNormal
        ActiveWorkbook.Worksheets("Projected Jurisdictional Date U").AutoFilter.Sort. _
            SortFields.Add Key:=Range("C3:C33000"), SortOn:=xlSortOnValues, Order:= _
            xlAscending, DataOption:=xlSortNormal
        ActiveWorkbook.Worksheets("Projected Jurisdictional Date U").AutoFilter.Sort. _
            SortFields.Add Key:=Range("D3:D33000"), SortOn:=xlSortOnValues, Order:= _
            xlAscending, DataOption:=xlSortNormal
        ActiveWorkbook.Worksheets("Projected Jurisdictional Date U").AutoFilter.Sort. _
            SortFields.Add Key:=Range("AB3:AB33000"), SortOn:=xlSortOnValues, Order:= _
            xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Projected Jurisdictional Date U").AutoFilter. _
            Sort
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    
        Application.ScreenUpdating = False
        Sheets("Projected Jurisdictional Date U").Select
        Do While IsEmpty(Range("K" & Row).Value) = False
            CheckSKU = Range("C" & Row).Value
            CheckSKU2 = Range("C" & Row + 1).Value
            CheckRev = Range("D" & Row).Value
            CheckRev2 = Range("D" & Row + 1).Value
            ActMDD = Range("AB" & Row).Value
            ActMDD2 = Range("AB" & Row + 1).Value
            If CheckRev = "A" Then
                CheckRevPrevious = "A"
            Else
                CheckRevInteger = Asc(CheckRev) - 1
                CheckRevPrevious = Chr(CheckRevInteger)
            End If
            Condition = Range("AB" & Row).Value
            Condition2 = Range("AB" & Row + 1).Value
            SalesOrgDmd = Range("K" & Row + 1).Value
            If CheckSKU Like CheckSKU2 And IsEmpty(Condition) Like IsEmpty(Condition2) And SalesOrgDmd = "Y" Then
                ActMDDPrevious = 0
                RowPrevious = 3
                SalesOrgDmdPrevious = Range("K" & RowPrevious).Value
                ConditionPrevious = Range("AB" & RowPrevious).Value
                Do While IsEmpty(Range("E" & RowPrevious).Value) = False
                
                    If Range("E" & RowPrevious).Value = CheckSKU2 & "_" & CheckRevPrevious And SalesOrgDmdPrevious = "Y" And IsEmpty(ConditionPrevious) = "False" Then
                        If CheckRev = "A" Then
                            ActMDDPrevious = 0
                        Else
                            ActMDDPrevious = Range("AB" & RowPrevious).Value
                        End If
                        Exit Do
                    Else
                    End If
                    RowPrevious = RowPrevious + 1
                    SalesOrgDmdPrevious = Range("K" & RowPrevious).Value
                    ConditionPrevious = Range("AB" & RowPrevious).Value
                Loop
                If CheckRev Like CheckRev2 Then
                ElseIf ActMDD2 < ActMDD And IsEmpty(Condition2) = "False" Then
                    Sheets("On Hand Details").Select
                    OnHandRow = 4
                    Do While IsEmpty(Range("E" & OnHandRow).Value) = False
                        If Range("E" & OnHandRow).Value = CheckSKU2 & "_" & CheckRev2 Then
                            OnHandUnReInTr = Range("O" & OnHandRow).Value + Range("T" & OnHandRow).Value
                            If OnHandUnReInTr > 0 Then
                                Range("A" & OnHandRow, "Z" & OnHandRow).Select
                                Selection.Copy
                                Sheets("Batch Identification").Select
                                Range("D" & PasteRow).Select
                                ActiveSheet.Paste
                                Range("A" & PasteRow).Value = "Act MDD prior prev Rev"
                                Range("B" & PasteRow).Value = CheckRev2
                                Sheets("On Hand Details").Select
                                PasteRow = PasteRow + 1
                            Else
                            End If
                        Else
                        End If
                    OnHandRow = OnHandRow + 1
                    Loop
                    Sheets("Projected Jurisdictional Date U").Select
                End If
                Delta = Asc(CheckRev2) - Asc(CheckRevPrevious)
                If CheckRevPrevious Like CheckRev2 And Delta < 2 Then
                ElseIf ActMDD2 < ActMDDPrevious And IsEmpty(Condition2) = "False" Then
                    Sheets("On Hand Details").Select
                    OnHandRow = 4
                    Do While IsEmpty(Range("E" & OnHandRow).Value) = False
                        If Range("E" & OnHandRow).Value = CheckSKU2 & "_" & CheckRev2 Then
                            OnHandUnReInTr = Range("O" & OnHandRow).Value + Range("T" & OnHandRow).Value
                            If OnHandUnReInTr > 0 Then
                                Range("A" & OnHandRow, "Z" & OnHandRow).Select
                                Selection.Copy
                                Sheets("Batch Identification").Select
                                Range("D" & PasteRow).Select
                                ActiveSheet.Paste
                                Range("A" & PasteRow).Value = "Act MDD prior prev Rev"
                                Range("B" & PasteRow).Value = CheckRev2
                                Sheets("On Hand Details").Select
                                PasteRow = PasteRow + 1
                            Else
                           End If
                        Else
                        End If
                    OnHandRow = OnHandRow + 1
                    Loop
                    Sheets("Projected Jurisdictional Date U").Select
                Else
                End If
            Else
            End If
            Row = Row + 1
        Loop
        Application.ScreenUpdating = True
        Sheets("Batch Identification").Select
        Range("A2").Select
    End Sub

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,754

    Re: Runtime error 91

    When you run the code and get the error message, click on debug and tell us which line of code is highlighted.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    03-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Runtime error 91

    Oh yeah sorry - that would help, right?

    it's this line:


        ActiveWorkbook.Worksheets("Projected Jurisdictional Date U").AutoFilter.Sort. _
            SortFields.Clear

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,008

    Re: Runtime error 91

    Is there a filter set on that sheet?
    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Registered User
    Join Date
    03-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Runtime error 91

    No there is no filter on that sheet.

  6. #6
    Registered User
    Join Date
    03-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Runtime error 91

    Oh wait - now that you were asking about the filter. I put now one on the sheet and it's working now.
    I just thought he would filter automatically...?

    OK, but it's working. Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Runtime error '1004': Paste special method of range class error.
    By Daryl Zer0 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-05-2014, 01:44 AM
  2. [SOLVED] VBA Error: Runtime Error 1004: AutoFilter method of Range class failed
    By jl22stac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-03-2013, 07:27 PM
  3. [SOLVED] Range error in code, runs alone but not inside my full program, giving runtime error 1004
    By charizzardd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-23-2012, 03:34 PM
  4. runtime error 3265 error in a VBA Query to pull info from ERP Database
    By NBVC in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-12-2010, 03:59 PM
  5. Excel xmlHTTP object error message - system/runtime error
    By Porky2007 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-23-2007, 09:36 AM

Tags for this Thread

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.6.0 RC 1