+ Reply to Thread
Results 1 to 10 of 10

Validating contents of a cell on input based on the contents of another cell

  1. #1
    Registered User
    Join Date
    12-02-2012
    Location
    Sydney, Au
    MS-Off Ver
    Excel 2007
    Posts
    7

    Validating contents of a cell on input based on the contents of another cell

    Hi all,

    Currently working on some code to do something that's a fair bit ahead of anything I've done in VBA before, so I'm turning to you fine people for assistance!

    What I'm trying to work on is this:

    In Column G, the user can select one of 7 options to provide something to an employee. Based on the option selected they then need to go into column S suggest the length of provision, and then column T to suggest the value of the provision.

    Each of the 7 options has different valid lengths and values.

    I want to set up a macro so that when they enter something in either S or T it checks that what they have entered falls within the range for that option, and if not pops up an error until they suggest something appropriate.

    Any suggestions? I've had a really good google for this, and can't find anything that might be appropriate.

    Thanks in advance for any help!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,360

    Re: Validating contents of a cell on input based on the contents of another cell

    Rather than make it trial and error, what don't you set up dependent drop down boxes. You'd probably still need code to clear the dependent values but the code would be much simpler. Look at the Contextures web site for advice.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    12-02-2012
    Location
    Sydney, Au
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Validating contents of a cell on input based on the contents of another cell

    Quote Originally Posted by TMShucks View Post
    Rather than make it trial and error, what don't you set up dependent drop down boxes. You'd probably still need code to clear the dependent values but the code would be much simpler. Look at the Contextures web site for advice.


    Regards, TMS
    The issue is that the value is not from a list, but can be anything between X and Y in both cases, otherwise I would have done data validation with some indirects in excel.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,360

    Re: Validating contents of a cell on input based on the contents of another cell

    Please post a sample workbook and indicate the ranges and values.

    Regards, TMS

  5. #5
    Registered User
    Join Date
    12-02-2012
    Location
    Sydney, Au
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Validating contents of a cell on input based on the contents of another cell

    No problem. The categories and ranges are as per the attached, with the cells mentioned appearing as per the below.

    Options 4-7 don't need a %age checking as they are non-financial in nature.

    i'm prepopulating the allowed values based on a Vlookup, just need to make sure people are playing by the rules in terms of their own inputs!

    Example Ranges.xls
    Last edited by Saigonet; 12-02-2012 at 11:03 PM.

  6. #6
    Registered User
    Join Date
    12-02-2012
    Location
    Sydney, Au
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Validating contents of a cell on input based on the contents of another cell

    With sincere apologies to anyone who writes VBA for a living (as the following will make your eyes bleed.

    I managed to get it working like so -

    Please Login or Register  to view this content.

    I'm pretty sure that there's going to be a better way of doing this though!

    The above is dependent on them hitting enter to put the value in. I do know the odd person who uses arrow keys which will make all of the above fall over :/ If someone can suggest a way around that it would be appreciated!

  7. #7
    Registered User
    Join Date
    12-02-2012
    Location
    Sydney, Au
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Validating contents of a cell on input based on the contents of another cell

    Above still doesnt quite work :/

    Suspect its a problem with my "If Not And stuff"...

  8. #8
    Registered User
    Join Date
    12-02-2012
    Location
    Sydney, Au
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Validating contents of a cell on input based on the contents of another cell

    Flipped them to "If/Or" and changed the direction of the inequalities and it now works. The only problem now is that once it clears the contents, the value of the cell is invalid and it throws it into an infinite loop. Oh dear.

  9. #9
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Validating contents of a cell on input based on the contents of another cell

    Hello Saigonet,

    Your WorkBook contains no formulas or dropdowns, making it very difficult to try and understand what you are after.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  10. #10
    Registered User
    Join Date
    12-02-2012
    Location
    Sydney, Au
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Validating contents of a cell on input based on the contents of another cell

    Quote Originally Posted by Winon View Post
    Hello Saigonet,

    Your WorkBook contains no formulas or dropdowns, making it very difficult to try and understand what you are after.
    Its explained in the text in the first post - Basically just only allowing certain values in cells based on the contents of another cell. Because they are not discrete values, I couldn't use a drop down to do it.

    I got there in the end though, albeit it looks horrible. Just had to turn off and on application events

+ 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