+ Reply to Thread
Results 1 to 10 of 10

VBA alternative to a PIVOT table

  1. #1
    Forum Contributor
    Join Date
    06-24-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2016
    Posts
    124

    VBA alternative to a PIVOT table

    Hi all,

    Needing help with data manipulation to show only the lines the represent the end result for an employees pay period.

    Brief contexts:
    An employee can be paid certain elements such as Ordinary hours, Leave hours, overtime etc.. Each row of data is made up of one of these elements.
    One row per element however employee can have multiple rows per payperiod.


    Where things get interesting is, employees can have additional retrospective lines, which are displayed as either a negative or positive.
    A negative means that it will negate the pay element where it was previously applied.
    A positive means that the value of the pay line is added to the element that was previously applied.

    If you are still following then great!, if not I totally understand.

    I have attached an example book of what I have done so far, which primarily consists of adding "DELETE" flags then delete the marked rows at the end, however this is
    a) far too slow, when i have over 300K rows
    b) not entirely the most robust solution.

    The reason this won't work in a PIVOT table, is where an employee has a negative retrospective line with a different rate of pay. The only options become showing the MAX of MIN rate.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,877

    Re: VBA alternative to a PIVOT table

    Nothing attached
    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
    Forum Contributor
    Join Date
    06-24-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2016
    Posts
    124

    Re: VBA alternative to a PIVOT table

    Hi, Sorry now attached

    Also, i have commented out the "Delete" sub, so you can see what lines it is deleting
    Attached Files Attached Files

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,229

    Re: VBA alternative to a PIVOT table

    Also, i have commented out the "Delete" sub
    Where?

    What are you actually wanting to achieve here...delete all rows with -(negative) values in Col R?
    What is the actual criteria...
    I suggest you explain the process...step by step
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  5. #5
    Forum Contributor
    Join Date
    06-24-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2016
    Posts
    124

    Re: VBA alternative to a PIVOT table

    I have made the code work, except it runs pretty slowly, about 1.5 seconds per each EMP_REF_unq statement.

    Any ideas on how to speed this up?

    here is the code:

    Please Login or Register  to view this content.

  6. #6
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,229

    Re: VBA alternative to a PIVOT table

    Well...as you have not answered any of post 4 questions...And your code is missing functions...
    Not possible to understand what you are actually wanting to achieve...
    Last edited by sintek; 08-12-2020 at 02:41 AM.

  7. #7
    Forum Contributor
    Join Date
    06-24-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2016
    Posts
    124

    Re: VBA alternative to a PIVOT table

    Sorry sintek

    The initial objective was to delete rows that have been superseded by another row (This happens when there is a wage element such as ORD that is a negative value of equal amount of hours.
    The code i posted is the modified version that will search for the wage element and add or subtract hours based on the found results (if it is positive or neg) then remove the found lines (if any found)

    To summarize in steps:
    1. copies the pay period into a temp sheet from the master file for an individual employee
    2. for each row in the temp sheet, search the wage element (ord hours, overtime etc...)
    3. if results are found (more than the value that starts the search), then add the hours associated to that found value to the search value hours. Then delete the hours from the result element and add the text "DELETE" to the end column (this is for the deletion of the not useful rows at the end)
    4. if not found, then do nothing (this means there was no superseding entry for that wage element)
    5. when all wage elements are looked through then run the "Delete" function which is not listed in the code
    6. copy results to a different sheet
    7. Go to the next loops to the top again.


    Hopefully this covers it! let me know if i need to clarify something

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,229

    Re: VBA alternative to a PIVOT table

    I see unnecessary steps...If the idea is to delete specific rows based on criteria then why not just have one action to do everything...Why copy to temp sheets and manipulate data etc etc...

    Is the idea to loop unique values in MultiWage Tab ... do some checks and delete rows for that unique reference... If so...
    What are the criteria or calculations that one needs to check...

    This happens when there is a wage element such as ORD that is a negative value of equal amount of hours.
    According to the above quote...Multiwage Tab has no such criteria...or am I missing something...

    Edit...

    In row 8 and 3... do these two cancel each other out...meaning delete them both or only the negative figure...?
    In row 9 and 4... do these two cancel each other out...meaning delete them both or only the negative figure...?
    Last edited by sintek; 08-12-2020 at 03:47 AM.

  9. #9
    Forum Contributor
    Join Date
    06-24-2013
    Location
    New Zealand
    MS-Off Ver
    Excel 2016
    Posts
    124

    Re: VBA alternative to a PIVOT table

    The only real purpose of the temp sheet, is so i can see pause break the code while writing it to compare the output with with original. if the process of the temp sheet really adds to the time of the code running, i can remove it.

    an example of how it should work...

    Row 2 is the first entry of ORD (Ordinary hours) of 16.
    Row 7 is a negative of the same wage type description so will deduct two hours from Row 2
    Row 19 is a negative for a different period so will not affect the Row 2.
    The end result is Row 2 to having 14 hours

    I forgot to mention, to make the code work in the original book that I uploaded, you will need to put this formula in Col X which acts as a helper column

    Please Login or Register  to view this content.
    In summary, the code looks for the value in Col X and if found, then adds the hours to the row the search was based off. so if the hours added are neg or pos, it will still calculate correctly.

    Hope this makes more sense, sorry for the ambiguous postings

  10. #10
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,229

    Re: VBA alternative to a PIVOT table

    Row 7 is a negative of the same wage type description so will deduct two hours from Row 2
    deduct 2 hours from time...What about deduct R100 from Amount and then does this row 7 get deleted?

    Do rows 3 and 8 cancel each other out?
    Do rows 4 and 9 cancel each other out?

    I suggest uploading a sample file with a before and after expected scenario so that members can see exactly what you are wanting to achieve...
    Good luck...

    Untitled.png
    Last edited by sintek; 08-12-2020 at 06:19 AM.

+ 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. Alternative to Pivot table
    By joshuar in forum Excel General
    Replies: 1
    Last Post: 06-15-2016, 05:00 AM
  2. Alternative to a Pivot table to create a list
    By simbalyon303 in forum Excel General
    Replies: 15
    Last Post: 01-09-2015, 06:34 PM
  3. Pivot table alternative
    By nick2price in forum Excel General
    Replies: 4
    Last Post: 08-16-2013, 06:12 AM
  4. [SOLVED] Alternative for Pivot table - row data
    By mmor79 in forum Excel General
    Replies: 2
    Last Post: 04-04-2012, 02:15 PM
  5. [SOLVED] Alternative for Pivot table - row data
    By mmor79 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-02-2012, 07:35 PM
  6. Alternative need for Pivot Table
    By ronanm in forum Excel General
    Replies: 2
    Last Post: 01-21-2011, 11:06 AM
  7. Alternative to Pivot Table
    By papaexcel in forum Excel General
    Replies: 16
    Last Post: 07-01-2009, 04:18 PM

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