+ Reply to Thread
Results 1 to 16 of 16

Inserting value in a cell when element is picked from a dropdown list in another cell

  1. #1
    Registered User
    Join Date
    10-07-2014
    Location
    Salvador da Bahia, Brazil
    MS-Off Ver
    2013
    Posts
    39

    Post Inserting value in a cell when element is picked from a dropdown list in another cell

    Hi all. I have been trying to create a macro by reading all related posts here but I am not experienced with macros, so no success.
    What I am trying to do is:
    There is a list in column E in worksheet named "Workflow". Users can pick either "BRL", "EUR", or "USD" from this list. Whenever "BRL" is selected, cells in the same row in columns M, N, O, P must show the text "n/a". If the others are selected or if the cell is blank, macro should take no action.
    I'm not sure whether this is important to say, but there's a conditional formatting applied to columns M, N, O, P: if "BRL" is selected, neither numbers nor texts can be entered (to prevent users from entering any value that would screw the final result). If either "EUR" or "USD" is selected, then user can enter positive numbers and cannot enter texts. This is already set and working fine. I don't want to over complicate and I think this should not be written in the macro but I don't know whether this would influence macro at all.

    Let me know if you guys need more information.

    I appreciate any help.

  2. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Inserting value in a cell when element is picked from a dropdown list in another cell

    You should post a worksheet. You can replace any sensitive data with dummy data. Make sure you are showing and explaining where and what you want the results of the changes in the drop down list to be.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  3. #3
    Registered User
    Join Date
    10-07-2014
    Location
    Salvador da Bahia, Brazil
    MS-Off Ver
    2013
    Posts
    39

    Re: Inserting value in a cell when element is picked from a dropdown list in another cell

    Hi skywriter. Thanks for the advice.
    If by "worksheet" you meant "screenshot", I added a couple of them down here.
    As you can see in the first picture, the dropdown list is in column E. When "BRL" is selected from that list cells in the same row in columns M, N, O, P must show "n/a". Currently, cells in columns M, N, O, P contains a formula
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    which you can see in the second picture. The problem is that this formula can be erased by any user.

    Any advice?

    I appreciate.
    Attachment 402935

    Attachment 402936

  4. #4
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Inserting value in a cell when element is picked from a dropdown list in another cell

    No I meant worksheet(the file), I can't test a picture or tell if there are any data issues or other things I should be aware of with a picture. I don't want to spend my time trying to recreate your sheet from scratch. You can make a copy and if you have sensitive data just replace it with dummy data. If you have hundreds of rows etc just delete most of them but be sure to leave enough to show what you need.

    To post a file reply to this thread, click the Go Advanced button and select the paperclip icon.

    View Pic

  5. #5
    Registered User
    Join Date
    10-07-2014
    Location
    Salvador da Bahia, Brazil
    MS-Off Ver
    2013
    Posts
    39

    Re: Inserting value in a cell when element is picked from a dropdown list in another cell

    Oh! Wow! I didn't know that. Thanks for the explanation.
    So here's the file.
    Thank you.
    Attachment 402942

  6. #6
    Valued Forum Contributor bulina2k's Avatar
    Join Date
    11-20-2012
    Location
    Urziceni, Ialomita, Romania
    MS-Off Ver
    2019 and 365
    Posts
    861

    Re: Inserting value in a cell when element is picked from a dropdown list in another cell

    hi there adriano.r.marques
    try this code in your worksheet change event:

    Please Login or Register  to view this content.
    Last edited by bulina2k; 06-23-2015 at 05:25 PM.
    .. and don't forget to have fun!
    Bogdan.

    mark SOLVED and Add Reputation if my answer pleases you

  7. #7
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Inserting value in a cell when element is picked from a dropdown list in another cell

    Quote Originally Posted by adriano.r.marques View Post
    Oh! Wow! I didn't know that. Thanks for the explanation.
    So here's the file.
    Thank you.
    Attachment 402942
    Okay if you right click on the worksheet name tab and choose view code, then you can paste this into the window that comes up. You might see your other code and that will tell you that you are in the right place.

    This simply first of all checks to make sure you changed only one cell and that the cell you changed was from E3 to E500, you can change that if it's too much or too little. If the value of the cell is BRL you get n/a in M-P if not it's empty.

    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor bulina2k's Avatar
    Join Date
    11-20-2012
    Location
    Urziceni, Ialomita, Romania
    MS-Off Ver
    2019 and 365
    Posts
    861

    Re: Inserting value in a cell when element is picked from a dropdown list in another cell

    hi there skywriter
    still your code does not prevents the users from modifying values in M-P columns

  9. #9
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Inserting value in a cell when element is picked from a dropdown list in another cell

    Quote Originally Posted by bulina2k View Post
    hi there skywriter
    still your code does not prevents the users from modifying values in M-P columns
    It's not meant to, he has data validation in place.
    He was using a formula to put n/a in the cell if someone picked BRL, the data validation keeps them from entering a value. The problem is if they pick something other than BRL then those cells can be manipulated, but in so doing destroys his formula, so n/a will no longer be in the cell if it gets changed back to BRL.

  10. #10
    Registered User
    Join Date
    10-07-2014
    Location
    Salvador da Bahia, Brazil
    MS-Off Ver
    2013
    Posts
    39

    Re: Inserting value in a cell when element is picked from a dropdown list in another cell

    Hi bulina2k. Thank you so much for your reply. I don't really know why but I think skywriter is right: with his code I could pick "BRL" in the list and M-P cells showed "n/a" and if I changed from "BRL" to "USD" or "EUR", M-P cells then appeared blank. That is really what I wanted!

    It seems so simple I wish I could have written the code myself.
    It's just that I can't understand it.

    Thank you guys. You were great.

  11. #11
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Inserting value in a cell when element is picked from a dropdown list in another cell

    Glad you are happy.

    If your original request is fulfilled please click the Thread Tools drop down box above your first post and choose solved.

    If you are happy with my help, please consider clicking the add reputation button in the lower left hand corner of this post.

  12. #12
    Registered User
    Join Date
    10-07-2014
    Location
    Salvador da Bahia, Brazil
    MS-Off Ver
    2013
    Posts
    39

    Re: Inserting value in a cell when element is picked from a dropdown list in another cell

    Hi, guys. Sorry to bother you again with this. As I thought I was a smartass, I tried to apply the VBA code yous guys created in another function but it isn't working.
    This time I want cells in column R to show either "C" or "O" depending on the value selected from a list in the same row in column Q. So if user selects either "Canceled" or "Withdrawn" in column Q, same row column R shows "C". If any other value is selected from the list in column Q, then user can select (or type) either "O" or "C" in same row column R (ideally, cell would show "O" as default). Finally, if none value is selected from the list, then same row column R is blank.

    As to start out, I decided to test whether one of these would work out by editing the previous code you guys provided:

    Please Login or Register  to view this content.
    Obviously it didn't work. What am I doing wrong?
    Last edited by adriano.r.marques; 06-25-2015 at 01:01 PM. Reason: Couldn't make it as clear before.

  13. #13
    Valued Forum Contributor bulina2k's Avatar
    Join Date
    11-20-2012
    Location
    Urziceni, Ialomita, Romania
    MS-Off Ver
    2019 and 365
    Posts
    861

    Re: Inserting value in a cell when element is picked from a dropdown list in another cell

    hi there!
    I think you should use select case statements (in Worksheet_Change event):

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    10-07-2014
    Location
    Salvador da Bahia, Brazil
    MS-Off Ver
    2013
    Posts
    39

    Re: Inserting value in a cell when element is picked from a dropdown list in another cell

    Hi bulina2k. Thank you for your reply. I copied the code you provided into the VBA code of my worksheet but I got the error message "Compile error: Ambiguous name detected: Worksheet_Change". Screenshot below:

    Screenshot 2015-06-25 16.07.06.png

    So I tried changing private sub titles from "Worksheet_Change" to "Worksheet_Complete". When I select an entry from the list in a cell in column Q nothing happens.

  15. #15
    Valued Forum Contributor bulina2k's Avatar
    Join Date
    11-20-2012
    Location
    Urziceni, Ialomita, Romania
    MS-Off Ver
    2019 and 365
    Posts
    861

    Re: Inserting value in a cell when element is picked from a dropdown list in another cell

    as you can see (from your picture) there is already code in Worksheet_Change event (skywriter's code) so because you can't have two Worksheet_Change subs you will have to use that same sub.
    Put my code:
    Please Login or Register  to view this content.
    right before 'End sub' (and of course delete the second Worksheet_change)

  16. #16
    Registered User
    Join Date
    10-07-2014
    Location
    Salvador da Bahia, Brazil
    MS-Off Ver
    2013
    Posts
    39

    Re: Inserting value in a cell when element is picked from a dropdown list in another cell

    Hi bulina2k. Thank you so much. It's working beautifuly.
    I'm curious about something. When I select one single cell in column Q and hit the delete key, whatever is in the same row column R is automatically gone. However, when I select multiple cells in column Q and hit the delete key, whatever is in the same row column R is kept. It happens with previous skywriter's code too. It isn't a problem at all as I can always delete it manually, but why is that?

    Again, thank you for your help.
    Last edited by adriano.r.marques; 06-25-2015 at 04:44 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Formula to show an adjacent cell to the one picked in a data validation list
    By sengatwork in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-14-2013, 02:30 PM
  2. How to Lock a cell based on option picked from a data validation list
    By dp0875 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-31-2013, 10:53 AM
  3. Copy comment from list element to another cell
    By IBMiGuy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-27-2011, 04:21 PM
  4. Replies: 21
    Last Post: 12-02-2009, 03:27 PM
  5. How validation dropdown list open when cell is picked?.
    By ron in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-21-2006, 08:45 PM

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