+ Reply to Thread
Results 1 to 2 of 2

Changing an excel formula to a Macro (Allows for more records)

Hybrid View

  1. #1
    Registered User
    Join Date
    06-27-2011
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    21

    Changing an excel formula to a Macro (Allows for more records)

    Hi guys,

    Im totally lost here. I need help converting an excel formula into a macro that will execute to sum specific cells depending on whether it is RED, YELLOW or GREEN.

    Let me explain what I would like to happen: In column 1, the user will enter a number. In column 2 next to it, the user will either enter R for red, Y for yellow, or G for green.

    I need a macro that will determine if the cell in column 2 is red, yellow or green, then take the number next to it, and sum it with all cells that are the same color. I was able to write a formula that will do this but I realized that I might be adding more or less records into this worksheet.

    I'm thinking a loop of some sort, that will determine the first record and the last record, then look in column 2 for all cells that contain R and then sum. Then loop again for Y and then sum. Then loop agin for G then sum.

    Thank you so much for your time!

    I have attatched the file that will give you an example of what I am talking about.
    Attached Files Attached Files

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Changing an excel formula to a Macro (Allows for more records)

    1) move your totals to separate columns so they do not interfere with the additions you will make later
    2) use the SUMIF() function to do the adding.


    No VBA needed.
    Attached Files Attached Files
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ 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