+ Reply to Thread
Results 1 to 4 of 4

Filtering details onto a different worksheet

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-24-2010
    Location
    North West UK
    MS-Off Ver
    2013
    Posts
    112

    Filtering details onto a different worksheet

    Hi guys,

    A somewhat complicated one for me.

    I have a huge spreadsheet (attached) on it is a list of all my vehicles, what I want to do is somehow get a macro that will check the whole sheet and look for entries of unrecorded mileage (for example see line 1228) for each vehicle.

    What I would like it to do then is on another sheet in the workbook is draw out all the entries so that the new sheet will show the following:

    The registrations of the vehicles that have unrecorded mileage (if we use the example on line 1228 you will see that on line 1223 is the vehicle registration)
    The date before the unrecorded mileage and the date after for each registration with unrecorded mileage (with the driver name)
    The unrecorded mileage amount (the entry on line 1228 for example)

    I'm not sure if all this can be done. The report this data comes from would be generated weekly so the length of the spreadsheet will increase or decrease so can the macro allocate for that by looking at the whole sheet rather than a specific range.

    Any suggestions would be great!

    Thanks,
    Lew

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Filtering details onto a different worksheet

    This is fairly straightforward, using Power Query:

    let
        Source = Excel.Workbook(File.Contents("C:\Temp\V6 - All vehicle movements incl missing miles for period.xls"), null, true),
        SheetData = Source{[Name="V6 - All vehicle movements incl"]}[Data],
        #"Added Custom" = Table.AddColumn(SheetData, "Registration", each if [Column2] = null then [Column1] else null ),
        #"Filled Down" = Table.FillDown(#"Added Custom",{"Registration"}),
        #"Reordered Columns" = Table.ReorderColumns(#"Filled Down",{"Registration", "Column1", "Column2", "Column3", "Column4", "Column5", "Column6", "Column7", "Column8", "Column9", "Column10", "Column11", "Column12", "Column13", "Column14", "Column15", "Column16", "Column17", "Column18", "Column19", "Column20"}),
        #"Removed Top Rows" = Table.Skip(#"Reordered Columns",9),
        #"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true]),
        #"Renamed Columns" = Table.RenameColumns(#"Promoted Headers",{{List.First(Table.ColumnNames(#"Promoted Headers")), "Registration"}}),
        #"Filtered Blank Rows" = Table.SelectRows(#"Renamed Columns", each ([Name] <> null and [Name] <> "Name")),
        #"Added Index" = Table.AddIndexColumn(#"Filtered Blank Rows", "Index", 0, 1),
        #"Added Previous Date" = Table.AddColumn(#"Added Index", "Previous Date", each #"Added Index"{[Index]-1}[Start Date]),
        #"Added Previous Driver" = Table.AddColumn(#"Added Previous Date", "Previous Driver", each #"Added Index"{[Index]-1}[Name]),
        #"Added Previous ODO" = Table.AddColumn(#"Added Previous Driver", "Previous ODO", each #"Added Index"{[Index]-1}[Odo End]),
        #"Added Next Date" = Table.AddColumn(#"Added Previous ODO", "Next Date", each #"Added Index"{[Index]+1}[Start Date]),
        #"Added Next Driver" = Table.AddColumn(#"Added Next Date", "Next Driver", each #"Added Index"{[Index]+1}[Name]),
        #"Added Next ODO" = Table.AddColumn(#"Added Next Driver", "Next ODO", each #"Added Index"{[Index]+1}[Odo Start]),
        #"Removed Other Columns" = Table.SelectColumns(#"Added Next ODO",{"Registration", "Name", "Previous Date", "Previous Driver", "Previous ODO", "Next Date", "Next Driver", "Next ODO"}),
        #"Filtered Exceptions" = Table.SelectRows(#"Removed Other Columns", each Text.StartsWith([Name], "***"))
    in
        #"Filtered Exceptions"
    Change the filepath (in red) to point at your actual file.

    This will list all 'exception ' rows, with the Registration, Previous Date, Previous Driver, Previous ODO End, Next Date, Next Driver and Next ODO Start.
    If your source data file changes, simply refresh the query to update the exceptions list.

    Working example attached.
    Attached Files Attached Files
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Contributor
    Join Date
    03-24-2010
    Location
    North West UK
    MS-Off Ver
    2013
    Posts
    112

    Re: Filtering details onto a different worksheet

    That's perfect thank you.

    I don't know how to access the filepath bit though, could you let me know where I find that?

    Thank you.

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Filtering details onto a different worksheet

    You're using Excel 2013, right?

    Make sure the Power Query Add-In is enabled.

    From the POWER QUERY ribbon, click 'Launch Editor'. This will open the Power Query editor.

    You'll see each of the query steps in the pane on the right. Select the first step (Source) and edit the filepath in the formula bar.

    Click 'Close & Load' on the Home ribbon.


+ 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. Filtering Report on opening with correct details
    By Anthony.Preedy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-13-2017, 09:24 AM
  2. [SOLVED] Filter//paste data to 2 columns (title & details), autofill titles to match details
    By Frankximus3 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-18-2016, 03:10 AM
  3. Automatically include details from new worksheet in summary worksheet
    By shez in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-25-2013, 07:23 AM
  4. Replies: 6
    Last Post: 11-15-2012, 09:39 AM
  5. Macro to copy details from one worksheet to another
    By frhj2219 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-26-2012, 08:15 AM
  6. Replies: 0
    Last Post: 08-21-2012, 01:19 AM
  7. List file details into a worksheet, is it possible?
    By JoshS in forum Excel General
    Replies: 1
    Last Post: 12-15-2008, 11:51 PM

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