+ Reply to Thread
Results 1 to 5 of 5

Macro for Advanced Filter

  1. #1
    Registered User
    Join Date
    02-11-2011
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2003
    Posts
    13

    Macro for Advanced Filter

    Hey guys,

    I've been working on a spreadsheet and pretty much have it finished up except for this one extremely frustrating detail.

    The point of the sheet is to help caluculate material requirements. Column A in the example consists of text values that are being pulled from several cells on another sheet using & (for example, A2&" "&B2&" "&C2), and Column B is being pulled from the quantity of that material required for that line on the other sheet. There will be repeat values in column A.

    I need to pull the unique values out of A, and sum the required material for each one. The Advanced filter was giving me some issues when I was trying to filter the pulled in values (it was filtering the ""A2&" "&B2&" "&C2"" instead of the actual text strings they were pulling), hence why the macro pastes the values in columns C and D and does the filter on them instead.

    While this method actually works, I've noticed that it always pulls the first two lines out despite the fact that they may be unique. I've double checked everything to make sure that the values in Column A are being pulled in the same format, same spacing and all, yet it still pulls both the first and second row as unique values. Can anybody help me out and explain what might be going on here? Thanks.

    Also, if this belongs in the Excel functions section let me know, I wasn't sure which category it fell into more.
    Attached Files Attached Files

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Macro for Advanced Filter

    It's a simple: do not use merged cells. VBA doesn't handle those properly.



  3. #3
    Registered User
    Join Date
    02-11-2011
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Macro for Advanced Filter

    snb,

    thanks for the quick feedback, but the cells in question aren't merged. And unmerging their headings doesn't change the output. Any other thoughts?

  4. #4
    Registered User
    Join Date
    02-11-2011
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Macro for Advanced Filter

    Nevermind, I figured it out. Thanks though!

  5. #5
    Registered User
    Join Date
    04-30-2011
    Location
    Halifax, NS
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Macro for Advanced Filter

    The top cell in the range is considered to be the column heading (field name). The UNIQUE only applies to the cells below the heading. The modified code below appears to work.


    Range("E2").ClearContents
    Range("C2:C73").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range( _
    "E2"), Unique:=True
    Range("F3").Select
    ActiveCell.FormulaR1C1 = "=SUMIF(R3C3:R73C3,RC[-1],R3C4:R73C4)"
    Range("F3").Select
    Selection.AutoFill Destination:=Range("F3:F18"), Type:=xlFillDefault
    Range("E2") = "UNIQUE " & Range("E2")

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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