+ Reply to Thread
Results 1 to 7 of 7

Add Row and Value Based on Row Above

  1. #1
    Registered User
    Join Date
    11-09-2015
    Location
    Florida
    MS-Off Ver
    O365
    Posts
    61

    Add Row and Value Based on Row Above

    Hi All:

    Hoping to get some help with this issue that just came up. I get a report that I run my macro against, but the provider changed up the data by removing a row of data I need. I'd like to add that row back and do a calculation. Attaching a sample file.

    What I’d like to happen:

    - Look for the value “#Assigned Bldg Visited” in Column B, and insert a blank row on the next line. In the example, Row 7 has the first occurance of “#Assigned Bldg Visit,” so I’d like row 8 to become the blank row. This will run until the last instance of “#Assigned Bldg Visited” is found in Column B.

    Note: I’m focusing on the value “#Assigned Bldg Visited” because the raw data may have some blanks or extra rows, that I didn’t include in this sample.

    - In the newly inserted blank row, column B, insert and the value “% Assigned Bldg Visited.”

    - Do a calculation for each month based on the values found on the Assigned tab for each person and the “# Assigned Bldg Visited” for the month. For the sample data I only went out to April. The monthly calculation would be something like this for c35 on the Visit sheet: =C34/Assigned!B2. However, I think it would somehow have to know the number of for the specific person referenced in Column A on the“Assigned” tab. I haven’t thought this through yet, but something roughly like this:

    Take the name from the row with “# Assigned Bldg Visits” and match to the name on the “Assigned” tab and use the number in column b of the “Assigned” tab for the calculation “%Assigned Bldg Visited.”

    If this doesn’t make sense, I’ll try to do it visually with screenshots. Thanks a ton in advance for any assistance. This makes my head spin!

    Thanks
    WHH3

    P.S. On a side note, is it possible to run a formula in a macro, but have the out put to the cell be the value returned, rather than the formula. Just curious. Thx!
    Attached Files Attached Files

  2. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: Add Row and Value Based on Row Above

    Maybe you should explain the math further. You have for instance in your desired output in sheet in cell C8 the results of 60%, but no formula so we can see what you did and no explanation for why it's 60%. Above it is the number 3 and on the assigned sheet for John Doe is the number 4. So if you think how you came to the result of 60% based on those numbers, is obvious, it isn't.

    I'm not saying I'm going to work on your problem, I'm just saying I think you need to explain that or maybe I'm the only one that doesn't get it.

    I will however answer your last question.
    is it possible to run a formula in a macro, but have the out put to the cell be the value returned, rather than the formula
    Yes it's very common to do that. You can either run the formula in the cell with code and then basically do the equivalent of copying the cell and then paste special the value back in it, or you can do the calculation in code and paste the result into the cell.

  3. #3
    Registered User
    Join Date
    11-09-2015
    Location
    Florida
    MS-Off Ver
    O365
    Posts
    61

    Re: Add Row and Value Based on Row Above

    Thanks for the feedback Skywriter. On the Desired Output tab I did manually type in the values but it was simply: Number of Visits in January/number of Visits Assigned (on the Assigned tab). So John Doe is asked to visit his 5 Bldg's each month.* In January he made a total of 3 visits. 3/5 = 0.6 or 60% =c7/5 in this case. I think I'm doing that math correctly but been one of those days. Of course this bring to light another thing for me to think about...what if John Doe visits the same bldg twice in a month. Eh, one step at a time.

    *I just noticed I messed up the counts on the Assigned tab, which is probably why it didn't make sense to you. It should be 5, 5,6,4 for anyone working on this for me.

    Thanks for the answer on the formula pasting. I guess I never thought about pasting right over the forumla!

  4. #4
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: Add Row and Value Based on Row Above

    Okay thanks for the clarification.
    Regarding:
    Of course this bring to light another thing for me to think about...what if John Doe visits the same bldg twice in a month
    If you were to use a countif formula, you could set the criteria to greater than 0 and you would get how many buildings he visited regardless of how many times he visited each building.
    For example this formula in your visits sheet in cell C7, will still show three even if you change one or all of the 1's to a higher number.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Maybe later when I have more time I can help you with this. In the mean time maybe someone else will come up with a solution for you.

    Good Luck.
    Last edited by skywriter; 12-28-2015 at 05:56 PM.

  5. #5
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: Add Row and Value Based on Row Above

    Here you go.
    I set it up so you can use Control + q to run the macro.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by skywriter; 12-28-2015 at 10:04 PM.

  6. #6
    Registered User
    Join Date
    11-09-2015
    Location
    Florida
    MS-Off Ver
    O365
    Posts
    61

    Re: Add Row and Value Based on Row Above

    Oh good deal! Thanks for help and guidance! I should have some time this afternoon or tomorrow to tinker with this! I'll post how it goes!

  7. #7
    Registered User
    Join Date
    11-09-2015
    Location
    Florida
    MS-Off Ver
    O365
    Posts
    61

    Re: Add Row and Value Based on Row Above

    First pass at it - works perfectly! Thanks for taking the time to help out! Marking as Solved!

+ 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. Replies: 4
    Last Post: 05-19-2015, 11:53 PM
  2. [SOLVED] using SUMIFS and adding values based on multiple criteria based on selection from the drop
    By muheebrahman in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-25-2015, 12:55 AM
  3. [SOLVED] Highlight cell based on total quantity value based on repeated order numbers
    By PWilson0727 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-29-2014, 02:02 PM
  4. [SOLVED] Match existing column name, copy based based on matching name, drag till end
    By Amolvijay in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-19-2014, 04:20 PM
  5. Replies: 9
    Last Post: 04-18-2013, 09:27 AM
  6. Replies: 0
    Last Post: 12-28-2012, 06:24 PM
  7. Creating two different charts based on a single pivot table based on condition
    By exlnovice in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-26-2008, 06:21 AM

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