+ Reply to Thread
Results 1 to 12 of 12

Alert in VBA if amount exceeds 100%

  1. #1
    Registered User
    Join Date
    07-19-2009
    Location
    New Yoek
    MS-Off Ver
    Excel 2003
    Posts
    35

    Alert in VBA if amount exceeds 100%

    May I trouble anyone with this question.

    I was helped with a previous question on this thread

    http://www.excelforum.com/excel-work...ml#post2174267


    If I already have lets say 90% on B9 and I try to enter 15% on D9 it wont allow me because of the total being over 100%, but how can I have an alert to say Please enter 10% or less.

    Or

    If I already have lets say 50% on B9 and I try to enter 20% on D9 and I try to enter 50% F9 it wont allow me because of the total being over 100%, but how can I have an alert to say Please enter 70% or less (the sum of B9+D9).

    Can this be done using VBA?

    I've attached the file that has the data validation.

    Thanks..
    Attached Files Attached Files
    Last edited by Preatorian; 10-05-2009 at 03:07 PM. Reason: Solved by Mr. DonkeyOte

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Alert in VBA if amount exceeds 100%

    One possible approach outlined below

    Please Login or Register  to view this content.
    The above should account for the fact that in reality multiple % values can be assigned simultaneously (ie highlighting F9, H9 - entering 60% and pressing CTRL + ENTER)

    To insert the above

    -- First remove the Data Validation on the cell range

    -- Second right click on Tab against which the code is be applied - select View Code and paste above into resulting window ensuring Macros enabled thereafter.
    Last edited by DonkeyOte; 10-04-2009 at 12:56 AM.

  3. #3
    Registered User
    Join Date
    07-19-2009
    Location
    New Yoek
    MS-Off Ver
    Excel 2003
    Posts
    35

    Re: Alert in VBA if amount exceeds 100%

    Thank you, i will try this.

    One question, I additional line entries that need the same alert.

    On line B11,D11,F11,H11,J11,L11 as well as line 13,15,17,19, & 21, i have to enter % data that when combined can;t exceed 100%. How can this code work for them as well.

    Thanks,,,,

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Alert in VBA if amount exceeds 100%

    The approach will in part depend on whether or not you want to permit user entry of multiple cells simultaneously... eg highlight B9,D9 or B9,B11 etc - enter % and press CTRL + ENTER ... do you want to permit / prevent this ?

  5. #5
    Registered User
    Join Date
    07-19-2009
    Location
    New Yoek
    MS-Off Ver
    Excel 2003
    Posts
    35

    Re: Alert in VBA if amount exceeds 100%

    Well, in part, I dont think that they will simultaneously enter so many cells at a time, they should be entering one cell at a time, but maybe to prevent this it would be nice if it can be code, other wise, it doesnt need to be or whatever makes the code easier..

    Thanks.

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Alert in VBA if amount exceeds 100%

    Easier to prevent I think... perhaps the above will work for you ?

    Please Login or Register  to view this content.
    This code is to replace that provided previously

  7. #7
    Registered User
    Join Date
    07-19-2009
    Location
    New Yoek
    MS-Off Ver
    Excel 2003
    Posts
    35

    Re: Alert in VBA if amount exceeds 100%

    Thank You Veru Much.

    Perhaps I can bother you again.

    I added the code but it only seems to work for some entries and not all. I've attached the file with the code and highlighted the lines with WORKS or DON'T WORK so you can see which are working and which are not.

    Not sure what the problem is.
    Attached Files Attached Files

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Alert in VBA if amount exceeds 100%

    It doesn't work because the layout has changed since you told me of the additional requirements, ie:

    Quote Originally Posted by Preatorian
    One question, I additional line entries that need the same alert.

    On line B11,D11,F11,H11,J11,L11 as well as line 13,15,17,19, & 21,
    The code I provided looked only at Odd Rows (11,13,15 etc...) whereas in the last incarnation the layout has altered (and does not appear to be consistent in terms of row spacing).... to cater change the following:

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    (I noted you already revised the rngCells range per your layout)

  9. #9
    Registered User
    Join Date
    07-19-2009
    Location
    New Yoek
    MS-Off Ver
    Excel 2003
    Posts
    35

    Re: Alert in VBA if amount exceeds 100%

    Thanks again for your help.

    It performs great.

    I did the change becuase I know later on I will add additional layers and rows and wanted to see how to modify your code to get it to capture those additonal line entries.

    You've been so helpful friend.

    Thank You again for you help....

  10. #10
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Alert in VBA if amount exceeds 100%

    That's all good - was just trying to explain the cause of the intermittent failure in the earlier iteration.

    When I'm next in New Yoek you can buy me a bagel !

  11. #11
    Registered User
    Join Date
    07-19-2009
    Location
    New Yoek
    MS-Off Ver
    Excel 2003
    Posts
    35

    Re: Alert in VBA if amount exceeds 100%

    Wow, I wish I was in NEw YEok myself right now, although I live in Puerto Rico my heart and soul are in New Yoek. After being there for 23 years man,,,

    Question DonkeyOte, I thought i had completely finished but one question i have is,

    If I didn't have any empty lines and my data were all in rows one after the other like row 9 thru 40, no spaces in between, how can the code be changed to work accordingly...

    Thanks.

    And if ever u find yourself in PR I'll buy you a Corona and a Bacalaito. (Bacalaito is a batter cod fish strips deep fried)

  12. #12
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Alert in VBA if amount exceeds 100%

    If I didn't have any empty lines and my data were all in rows one after the other like row 9 thru 40, no spaces in between, how can the code be changed to work accordingly...
    Simply change the "valid" Range to

    Please Login or Register  to view this content.
    and then given you now know every row within the above range to be valid for testing you can remove the below line altogether

    Please Login or Register  to view this content.
    As for Bacalaito - sounds good - we Brits love our battered Fish !

    P.S FWIW I miss NY too... not been over for a while...

+ 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