+ Reply to Thread
Results 1 to 14 of 14

Excel Cell run code based on value

  1. #1
    Registered User
    Join Date
    03-14-2007
    Posts
    47

    Excel Cell run code based on value

    Hi, i need a bit of help, im looking to run a bit of code based on if a cell has a value of yes or no, If yes i want and inputbox to popup and then whatever value i type into that input box to show in the next columns cell, if no then to move to the column afters cell, for the yes/no cell im using data validation and this will be a yes/no cell all the way to the bottom of that columns end, so as you can see itll only popup with another input box if the next row down cell yes/no is selected and then an input box will popup asking for the value for the next columns cell if that makes sense?
    cheers

  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
    49,100

    Re: Excel Cell run code based on value

    You could do this with a Worksheet Change event monitoring the column with the data vailidation.

    However, you need to think through the process. What happens if the Input Box pops up and the user presses cancel/escape? What happens if they just press enter without inputting a value. Would you want to reset the original cell?

    You'd be best uploading a sample workbook with some typical data, identifying what you expect and what do when things go wrong ... as they inevitably will ;-)

    Regards
    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
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Excel Cell run code based on value

    A fairly basic example based on the yes/no's being entered in Column A. There may be other things you need to take into account.

    Please Login or Register  to view this content.

    Code need to go on the worksheet's code page. Right click on the sheet tab and select View Code.

    Dom
    Last edited by Domski; 02-03-2011 at 10:12 AM. Reason: Ooops
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  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
    49,100

    Re: Excel Cell run code based on value

    @Domski: do you need an "Exit Sub" after the "Application.Undo".

    I generally assume that, if multiple cells are being changed, the user might have selected a range and deleted the entries. It's difficult to cater for all the possibilities ...

    Regards

  5. #5
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Excel Cell run code based on value

    Quote Originally Posted by TMShucks View Post
    @Domski: do you need an "Exit Sub" after the "Application.Undo".

    I generally assume that, if multiple cells are being changed, the user might have selected a range and deleted the entries. It's difficult to cater for all the possibilities ...

    Regards
    Ooops, yes you're correct I missed that.

    I agree it can just be multiple deletions but I tend to put the limit to changing one cell in initially for ease and then if it doesn't suit the OP's requirement build further adaptations in later. Just my approach.

    Dom

  6. #6
    Registered User
    Join Date
    03-14-2007
    Posts
    47

    Re: Excel Cell run code based on value

    Thank you very much thats helped greatly and sorted my problem, just one more question, in relation to the above i need the same type of function but instead of a Inputbox i would like a Countif type function, if once cell has a value and another cell in the same row has a value inside it then it would count it, so im guessing it would involve and AND and Countif?
    e.g COUTIF B2="Value" and C2=Value.....but only count if they both have yes as the answer otherwise it wouldnt count it if it was just the one?
    thank again

  7. #7
    Registered User
    Join Date
    03-14-2007
    Posts
    47

    Re: Excel Cell run code based on value

    if its possible as ive incorporated some code where i have a button that copies a a sheet and renames it to a month i would like it to only count the value from the month sheet the user selects?

  8. #8
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Excel Cell run code based on value

    I have to admit I don't really follow what you are asking in either of your subsequent questions.

    Take a breath and try and explain the situation a bit more clearly (maybe with a bit more capitalisation and punctuation ).

    Dom

  9. #9
    Registered User
    Join Date
    03-14-2007
    Posts
    47

    Re: Excel Cell run code based on value

    sorry domski got a little excited trying to explain myself haha, what i mean is i need a function or coding that would count if different cells meet a certain criteria but they have to meet it in the same row...
    e.g. i have a column where it could contain lets say apples, oranges and pears
    and another column where it would contain a date for when one of the above was bought
    what i would like it to do is to count all the apples and as long as the date cell is not empty
    and the same again for oranges and pears.
    what ill do then is to total each count and multiply it by cost for each product (apples, oranges and pears have seperate prices) and then total all those costs up if that makes sense?

  10. #10
    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
    49,100

    Re: Excel Cell run code based on value

    I think you've got to the point where you *really* need to upload a sample workbook.

    Regards

  11. #11
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Excel Cell run code based on value

    I agree, it's making my head hurt just trying to read your questions/explanations.

    Dom

  12. #12
    Registered User
    Join Date
    03-14-2007
    Posts
    47

    Re: Excel Cell run code based on value

    there you go
    Attached Files Attached Files

  13. #13
    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
    49,100

    Re: Excel Cell run code based on value

    OK, something like:

    =SUMPRODUCT(--(D8:D17="Apples"),--(F8:F17<>"")) & " Apples " & SUMPRODUCT(--(D8:D17="Oranges"),--(F8:F17<>"")) & " Oranges " & SUMPRODUCT(--(D8:D17="Pears"),--(F8:F17<>"")) & " Pears "

    Regards

  14. #14
    Registered User
    Join Date
    03-14-2007
    Posts
    47

    Re: Excel Cell run code based on value

    Epic thank you very much all, its sorted all my problems out

+ 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