+ Reply to Thread
Results 1 to 20 of 20

Perform calculations for multiple rows based on specific column text

  1. #1
    Registered User
    Join Date
    03-31-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    15

    Perform calculations for multiple rows based on specific column text

    Hello Everyone!

    To start, I would consider myself an Excel novice so I apologize if this post is not quite as clear as it should be. I am looking for a way to have a macro look at a specific worksheet column, find any row that specific text in it then perform some SUMS and AVERAGEs of corresponding columns. I have been trying to figure this out on my own and I honestly do not know where to look.

    I have uploaded a sample document, I would appreciate any assistance for the following scenario:

    1. Check the "IO Classification by LUN" worksheet and find all rows that have the word "ESX" in the B Column
    2. For all of the conditions matching step 1, I would like to SUM columns S, BP, BQ, BY, BZ and I would like to AVERAGE columns AA, BM, BV
    3. I would like the output of the calculations to placed into the "Analysis" worksheet in the sample table provided.
    4. I would like to divide the results of the 'Capacity' by 1024

    The ultimate goal here is to be able to have a MACRO that looks for defined words and performs the same calculations based on these words. In my example above i specified ESX however I will have the following keywords in a final document:

    ESX
    DB
    LOG
    TEMPDB
    FILE
    BACKUP
    APP
    ARCHIVE
    EXCHANGE
    ORACLE
    SQL


    Thanks for any assistance you can provide, it is most appreciated.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Perform calculations for multiple rows based on specific column text

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    03-31-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Perform calculations for multiple rows based on specific column text

    WOW! This is amazing, thank you so much for putting this together. I have put this in as a visual basic macro and it is failing when it gets to ".Range("B1").Offset(j).Value = awf.Sum(wsIO.Range("S2:S" & LastRow).SpecialCells(xlCellTypeVisible)) / 1024" The error being seen is:

    "Run-time error '1004':
    No cells were found.


    Thanks again for your help on this, you are truly awesome a coding.


    Justin

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,972

    Re: Perform calculations for multiple rows based on specific column text

    Hi Im not sure if this is thcause of the error, but the contents of column S are text, not numbers. Highlight the range, and if you scroll back up, you will see a small yellow diamond - click on that and select "convert to number"
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Perform calculations for multiple rows based on specific column text

    It works for me using your Samples workbook. Are you using the same workbook as the example workbook you posted?

    There is a line of code that converts the text-numbers in column S to numeric values.

    The error is because it filters on a Type that doesn't exist in column B on the IO worksheet. I'm not sure why it's erroring. It should first test if a Type exists before filtering and avoid this error.

    Does it put any data on the Analysis sheet?
    Last edited by AlphaFrog; 03-31-2013 at 04:11 PM.

  6. #6
    Registered User
    Join Date
    03-31-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Perform calculations for multiple rows based on specific column text

    Thanks for the suggestion FDibbins! I tried this and it still fails with the same error at the same line. I wish I could provide more possible causes but this is out of my skill range.

    Thanks so much for the suggestions and help so far!


    Justin

  7. #7
    Registered User
    Join Date
    03-31-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Perform calculations for multiple rows based on specific column text

    Hi AlphaFrog,

    I am using the same workbook I uploaded. The code does successfully clear out the Analysis worksheet and put 'ESX' into the worksheet but then fails after that. Just to confirm, below are the steps I took to test this:

    1. Open the Excel File
    2. Went to the Developer tab on the Ribbon
    3. Opened Visual Basic
    4. Created a new module and pasted your code into it and saved the workbook as an Excel Macro enabled file (I did change the file name to keep track of it better).
    5. I then clicked on Macro in the Developer tab and ran the macro named 'analysis' and received the errors I posted back to you.

    Please let me know if I have done something wrong.

    Thanks so much!


    Justin

  8. #8
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Perform calculations for multiple rows based on specific column text

    You installed and ran the macro correctly.

    After it errors, do you see just the filtered rows for ESX on the IO worksheet?
    Is column S hidden?

  9. #9
    Registered User
    Join Date
    03-31-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Perform calculations for multiple rows based on specific column text

    Hi AlphaFrog,

    All data except for row 1 is hidden in the IO Classification sheet. Thanks again for the assistance on this.


    Justin

  10. #10
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Perform calculations for multiple rows based on specific column text

    Can you post your workbook again with the macro?

  11. #11
    Registered User
    Join Date
    03-31-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Perform calculations for multiple rows based on specific column text

    The file is attached, thanks!StorageSizing_NAR.xlsm

  12. #12
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Perform calculations for multiple rows based on specific column text

    The latest file and macro worked for me. I'm a bit stumped. There may be something different with autofiltering Excel 2010 versus Excel 2003, but I don't know what that difference is. I don't have 2010 to test with.

    This is just a guess. Add the red bit to this line of code...
    wsIO.Range("B1:B" & LastRow).AutoFilter 1, vTypes(i), xlAnd

  13. #13
    Registered User
    Join Date
    03-31-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Perform calculations for multiple rows based on specific column text

    Thanks AlphaFrog, I really appreciate your help with this. I have tried this in Excel 2007/2010/2013 and they aren't working, so there is probably some sort of difference from 2003.

    The extra code didn't work, I will keep looking into this on my side, most appreciated.


    Justin

  14. #14
    Registered User
    Join Date
    03-31-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Perform calculations for multiple rows based on specific column text

    Take a look at the attached file, it appears to be working 'better' but the data is not accurate. The below lined is the new line, the number 2 was a number 1.

    wsIO.Range("B1:B" & LastRow).AutoFilter 2, vTypes(i)

    When I say the data is not accurate, I tested this by manually filtering all of the "ESX" rows and doing an average of the read% column, the result should be 57 but the macro is returning 3139.42.

    Any thoughts on this?StorageSizing_NAR.xlsm

  15. #15
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Perform calculations for multiple rows based on specific column text

    The Read% column is column C on the Analysis sheet.
    Column C is the sum of column BP in the code.

    I didn't match the column headers in your workbook. I just put the data in the order you had listed them in your description. Can you adjust the code to analyse the proper columns or do you need me to figure it out?

    BTW: well done on figuring out the Autofilter field #. Not sure why that's different in 2010 vs 2003

  16. #16
    Registered User
    Join Date
    03-31-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Perform calculations for multiple rows based on specific column text

    AlphaFrog, you are awesome my friend. I have adjusted to match up the columns and everything appears to be correct now ( I will run all of the steps manually to doublecheck). This has a been a huge help to me, I really appreciate it. The final spreadsheet it attached if you want to review it.

    This is just the first step of an overall workflow I would like to automate but it is great progress.

    Cheers!


    Justin

    StorageSizing_NAR.xlsm

  17. #17
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Perform calculations for multiple rows based on specific column text

    Your code edits look correct. Well done and you're welcome.

    Be aware that the Read% column AA on the IO sheet has the values displayed as rounded whole numbers. The average function in the code uses the actual decimal values for calculation and not the rounded display values.

  18. #18
    Registered User
    Join Date
    03-31-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Perform calculations for multiple rows based on specific column text

    Quote Originally Posted by AlphaFrog View Post
    Your code edits look correct. Well done and you're welcome.

    Be aware that the Read% column AA on the IO sheet has the values displayed as rounded whole numbers. The average function in the code uses the actual decimal values for calculation and not the rounded display values.
    Thanks again! I am fine with the full decimal values. I am new to these forums, is there a 'solved' button that I can press and can I award you points of any sort?

    Thanks!


    Justin

  19. #19
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,972

    Re: Perform calculations for multiple rows based on specific column text

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

    Also, as a relatively new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  20. #20
    Registered User
    Join Date
    03-31-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Perform calculations for multiple rows based on specific column text

    Thanks FDibbins, I was looking for the 'solved' option and the reputation stuff.

    Cheers,

    Justin

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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