+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: VBA - Custom Filter

  1. #1
    Registered User
    Join Date
    11-25-2008
    Location
    Dublin, Ireland
    Posts
    10

    VBA - Custom Filter

    I have a bit of a weird one - -- --- -- -- --

    I have a huge spreadsheet with a list of Pay Periods in Column A (e.g. 200834) and Employee IDs in Column B (e.g. 3007).

    Columns C - ZZ contain figures, which are grouped into 3-5 column-wide blocks or related data. For example Columns E-G all contain tax data for a specific Employee in that specific Pay Period.

    What I want (need really) is a filter that lets me input a period number and a range of columns.

    The resulting columns (e.g. A-B AND E-G) then need to be copied to a new sheet.

    It would be amazing if I could also specify a sheet name in the filter.

    There's one other complication.

    The values on the sheet (which is sheet 1 of the WB) are generated via formulas on sheet 2 of the same WB.

    So, if I select a value on sheet two I actually see something like "='SETUP-TRESHOLDS-VARIABLES'!$K$8" in the Formula Bar; the cell however contains the resulting data (in that case 500.00).

    Any ideas?

    I'm in 2007 if that matters. (I've seen contradictory thoughts on that, btw.)

    Thanks so much guys and gals and help is mucho appreciado.

    --

    BTW> I have tried doing this about 10 different ways, cannibalizing other script, etc... but due to the dynamic nature of the data, nothing has worked...

  2. #2
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639
    Why don't you just keep all the data on one sheet but use Custom Views to see relevant data?
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  3. #3
    Registered User
    Join Date
    11-25-2008
    Location
    Dublin, Ireland
    Posts
    10

    because

    thanks for the response...

    we're parsing out the bits to different people who "don't need" to have access to the rest of the data and we're also stripping out the results into separate csv files for import...

    does that make sense?

    thanks!!!

  4. #4
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639
    It would still be easier to use one sheet for data
    Last edited by royUK; 11-25-2008 at 09:28 AM.
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  5. #5
    Registered User
    Join Date
    11-25-2008
    Location
    Dublin, Ireland
    Posts
    10
    will that make it impossible?

    we need to be able to globally update some of that data on the other sheet...so that's why... I suppose I could always just save the data sheet independently.. if that would help, consider it done!!!

    whatever it takes...

    --

    EDIT:

    I have created a single sheet version... can I post that here somehow
    Last edited by leelikchi; 11-25-2008 at 10:30 AM. Reason: I didn't want to double post.

  6. #6
    Registered User
    Join Date
    11-25-2008
    Location
    Dublin, Ireland
    Posts
    10
    wow! I'm amazed... I just tried a good excel programmer I know and they told me they couldn't do it...

    is this really that difficult?

    should I try and get a developer here to spend some time on it?

    shows what I know :P

  7. #7
    Registered User
    Join Date
    11-25-2008
    Location
    Dublin, Ireland
    Posts
    10
    still no answer?

  8. #8
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639
    It's difficult to help without seeing an example of the layout
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  9. #9
    Registered User
    Join Date
    11-25-2008
    Location
    Dublin, Ireland
    Posts
    10
    Quote Originally Posted by royUK View Post
    It's difficult to help without seeing an example of the layout
    D'oh!

    thanks Roy!!!

    I have attached the spreadsheet..


    does that help ?



    I really wasn't trying to be a jerk, just trying to figure out if it's something I need to spend developer resources on, etc.

    :P
    ----------------
    Now playing: Dead Letters Spell Out Dead Words / This Room Seems Empty Without You
    Attached Files Attached Files

  10. #10
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639
    It's still not very clear, do you want to filter the period & copy the data for that period?

    I filter for 200804

    Col B contains data P, Q & R
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  11. #11
    Registered User
    Join Date
    11-25-2008
    Location
    Dublin, Ireland
    Posts
    10
    Quote Originally Posted by royUK View Post
    It's still not very clear, do you want to filter the period & copy the data for that period?

    I filter for 200804

    Col B contains data P, Q & R
    Sorry Roy, you're a saint for being so patient.

    Yes, I want to be able to say 200804, Rows A-B, and J-L (for example).

    This would take all rows with the date 200804 (so like 100 rows) and copy and paste the data from those specific columns into a new workbook... or even better a new .csv document... but a new workbook/sheet is totally cool...

    heck, even just a new worksheet in the same workbook is super cool... I just have to do this all the time and it's so incredibly tedious + I have to show a few other this ridiculous task... and they always screw it up...

    so if I could make this easier for all of us (and produce a more trustworthy result) I would be so relived...

    thanks again Roy!!



    ----------------
    Now playing: Modest Mouse / Third Planet (Demo)

  12. #12
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639
    Do you need to keep the same format, with empty columns or just the columns containing data?
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  13. #13
    Registered User
    Join Date
    11-25-2008
    Location
    Dublin, Ireland
    Posts
    10
    same format please ... sometimes those column DO have data.... pain huh?

  14. #14
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639
    Try this

    Option Explicit
    
    Sub FilterToCSV()
    '
        Dim ans    As String
        Dim rCopy  As Range
        With Application
            .ScreenUpdating = False
            ans = InputBox("Enter date required. Format DDMMYY")
            If ans = "" Then Exit Sub
            ActiveSheet.UsedRange.AutoFilter Field:=1, Criteria1:=ans
            Set rCopy = ActiveSheet.UsedRange.SpecialCells(xlCellTypeVisible)
            Worksheets.Add
            ActiveSheet.Name = ans
            rCopy.Copy Sheets(ans).Cells(1, 1)
            ActiveSheet.Copy
            'change the directory to save to
            ActiveWorkbook.SaveAs Filename:="C:\" & ans & ".csv", FileFormat:=xlCSV, CreateBackup:=False
            ActiveWorkbook.Close True
            .DisplayAlerts = False
            Sheets(ans).Delete
            .DisplayAlerts = True
            .ScreenUpdating = True
        End With
    End Sub
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  15. #15
    Registered User
    Join Date
    11-25-2008
    Location
    Dublin, Ireland
    Posts
    10
    Quote Originally Posted by royUK View Post
    Try this

    Option Explicit
    
    Sub FilterToCSV()
    '
        Dim ans    As String
        Dim rCopy  As Range
        With Application
            .ScreenUpdating = False
            ans = InputBox("Enter date required. Format DDMMYY")
            If ans = "" Then Exit Sub
            ActiveSheet.UsedRange.AutoFilter Field:=1, Criteria1:=ans
            Set rCopy = ActiveSheet.UsedRange.SpecialCells(xlCellTypeVisible)
            Worksheets.Add
            ActiveSheet.Name = ans
            rCopy.Copy Sheets(ans).Cells(1, 1)
            ActiveSheet.Copy
            'change the directory to save to
            ActiveWorkbook.SaveAs Filename:="C:\" & ans & ".csv", FileFormat:=xlCSV, CreateBackup:=False
            ActiveWorkbook.Close True
            .DisplayAlerts = False
            Sheets(ans).Delete
            .DisplayAlerts = True
            .ScreenUpdating = True
        End With
    End Sub
    trying now....

    ok...

    well..

    that didnt' seem to work.

    it definitely does do half of it, but I probably (as usual) wasn't explicit...

    --

    In other words

    --

    Can I choose which columns I want to copy onto the new worksheet at runtime?

    And...

    Can I use the yyyymm format instead of the ddmmyy format for dates (just to mimic the existing date format)?

    Aren't I a jerk
    Last edited by leelikchi; 12-01-2008 at 11:12 AM.

+ 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.2.0