+ Reply to Thread
Results 1 to 13 of 13

For each if then issues

  1. #1
    Registered User
    Join Date
    09-20-2012
    Location
    Oklahoma
    MS-Off Ver
    Excel 2007
    Posts
    35

    For each if then issues

    I have attached a spreadsheet with a small set of sample data. I am wanting to write a macro that will plug in the commission rate in col C on sheet Data based on the person sales from col B using the table listed on sheet Rate table.
    I was thinking the best answer for this would be a for each/if then style macro. I know i could use a vlookup to do this and it is what i am currently doing however the amount of data I am needing to do this for and the number of times i have to do this each day i think the macro answer is better so if you guys could help that would be great. I have no experience writing a for each macro as i have only just started my macro side of excel.

    Thanks for all the help
    Attached Files Attached Files
    Last edited by chad portman; 09-23-2012 at 06:32 PM.

  2. #2
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,078

    Re: For each if then issues

    Nothing attached
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  3. #3
    Registered User
    Join Date
    09-20-2012
    Location
    Oklahoma
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: For each if then issues

    edited first post added attachment to the first post

  4. #4
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: For each if then issues

    Give this a try. Add .99 to the values in Column C on the Rate Table.

    Please Login or Register  to view this content.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  5. #5
    Registered User
    Join Date
    09-20-2012
    Location
    Oklahoma
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: For each if then issues

    I added the .99 as you said sorry i forgot that part when making a mock sample.
    However i added your code and told it to run and nothing happens at all.

  6. #6
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: For each if then issues

    Sorry I put the exit for in wrong. This will work

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    09-20-2012
    Location
    Oklahoma
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: For each if then issues

    Yea that works and super fast as well. WOW!! Now I just need to see if i can figure out what this code actually means and adapt it to my file. Due to the sensitive nature of my data I had to make the sample slightly different but I should be able to backwards engineer from here will help me more in the long run that way aways.

  8. #8
    Registered User
    Join Date
    09-20-2012
    Location
    Oklahoma
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: For each if then issues

    Ok so I understand most of the code and was trying to adjust it to my needs but my head is hurting so I thought I would try to ask it another way. I still need to do the same however there are two commission rate which are dependent on the state the sales rep is in. I have update the file with the new info and attached it here to see if it makes sense to you.
    Attached Files Attached Files

  9. #9
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: For each if then issues

    It would of been Nice if On the Rate Table Sheet where you have the "-" in column B, could of been the state code NC or SC. But this should work.

    Please Login or Register  to view this content.

  10. #10
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: For each if then issues

    Also everywhere theres a ">" or "<" sign we need to add an "=" ">=" "<=" So that if Sales happens to be a EVEN Amount it will find the rate. I wasnt thinking before, cause Im been watching football all day.

  11. #11
    Registered User
    Join Date
    09-20-2012
    Location
    Oklahoma
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: For each if then issues

    Please Login or Register  to view this content.
    What is the purpose of this part of the code since those cells are already blank?

  12. #12
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: For each if then issues

    Well lastrow I should of used in the For Next Loop but looks like I forgot to. The clearcontents just clears the range before running the macro again.

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    09-20-2012
    Location
    Oklahoma
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: For each if then issues

    This fixed the issues i was having thank you for your time hope your football games went as you hoped

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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