Consulting

Results 1 to 4 of 4

Thread: advanced filter code - subscript out of range/'Name' of object '_Worksheet' failed

  1. #1

    advanced filter code - subscript out of range/'Name' of object '_Worksheet' failed

    Hi,

    Can anyone offer me some advice where I'm going wrong with this VBA code/macro I'm trying to write please? I've exhausted my limited VBA knowledge and google!

    I'm trying to create a delivery summary in excel, I have the following sheets set up :

    Sheet2 (Continental Tracker) which contains data for multiple projects including delivery dates, I made this data including the column headers as named range "CONDATA".

    Sheet1 (Drop Downs Do Not Delete) has the criteria for certain columns - ie. delivery date, project status, I made this named range "CRIT1"

    Sheet11 (Delivery & On Hold Summary) contains the column headers I want to see in the summary, I made these column headers named range "DELHEADINGS".
    Sheet11 also contains a button linked to the macro.

    When I click the button I want to advanced filter "CONDATA" based on "CRIT1" and copy it to "DELHEADINGS".

    The code I'm using is :

    ' apply filter
    Range("CONDATA").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range("CRIT1"), CopyToRange:=Range("DELHEADINGS"), Unique:=False
    This worked for about a week but then just stopped working. After I added an errorcatcher code in it said - "Method 'Range' of object '_Worksheet' failed"

    I thought it was something to do with the fact I didn't specify the ranges are on different sheets, so I changed it to :

    ' apply filter
    Worksheets("Continental Tracker").Range("CONDATA").AdvancedFilter Action:=xlFilterCopy, _
        CriteriaRange:=Worksheets("Drop Downs Do Not Delete").Range("CRIT1"), _
        CopyToRange:=Worksheets("Delivery & On Hold Summary").Range("DELHEADINGS"), Unique:=False
    now it comes up with another error - "Subscript out of range" or "The extract range has a missing or illegal field name"

    Can someone help me out with where I've gone wrong please, I think I may be specifying the sheets wrong maybe but I'm not sure....

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Check the Defined Names on each Worksheet
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    thanks for the reply, I checked the defined names in Name Manager and they all seem ok :

    Capture.JPG

    Is it something to do with how I'm calling up sheets in the VBA code?

    or maybe where I have the named ranges (workbook) etc?

    Thanks

  4. #4
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    can you post your wokbook.
    see my signature to do that.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

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