+ Reply to Thread
Results 1 to 13 of 13

Autopopulate drop down if contains only one value

  1. #1
    Registered User
    Join Date
    10-12-2018
    Location
    NY,USA
    MS-Off Ver
    2016
    Posts
    7

    Question Autopopulate drop down if contains only one value

    Hi,

    I'm new to vba and will be starting to use vba alot more now.

    I'm trying to create dropdown's and have it autopopulate if there is only one value. The Validation's is pulling from Tables.
    For example column H is pulling base off of column G. But I want column H to autopopulate if it only has one value base off of column G.

    I tried to use this code below but I keep getting an error message Run-Time Error '1004' Method range of object_'worksheet' failed:

    Please Login or Register  to view this content.
    Any help is appreciated,

    Thanks!

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Autopopulate drop down if contains only one value

    You are probably creating an endless loop.

    Try

    Please Login or Register  to view this content.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    10-12-2018
    Location
    NY,USA
    MS-Off Ver
    2016
    Posts
    7

    Question Re: Autopopulate drop down if contains only one value

    Hi,

    Thanks for the reply!
    For some reason I still get an error message of the range, am I doing something wrong?? I might be incorporating it with my existing macro wrong.
    I have attached the excel workpaper for your reference without your macro for now, any guidance is appreciated.

    Thanks!
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Autopopulate drop down if contains only one value

    Ok

    I was right you are creating an endless loop but you basic program is wrong too.

    I got this to work

    Please Login or Register  to view this content.

    However it is a pointless bit of code because

    Please Login or Register  to view this content.
    Simply fills column H with the contents of G1.

    It simplifies down to

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 10-15-2018 at 04:11 PM.

  5. #5
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Autopopulate drop down if contains only one value

    With the code in the Workbook

    Try this version

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-12-2018
    Location
    NY,USA
    MS-Off Ver
    2016
    Posts
    7

    Re: Autopopulate drop down if contains only one value

    Hi,

    Thanks for the reply! I tried putting the code in, but it seem to clear the whole column H instead of pulling the value automatically if it has only one value.

    Am I doing something wrong?

    Thanks again for the help.

  7. #7
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Autopopulate drop down if contains only one value

    Which code are you looking at?

    Neither attempt to operate as you describe.



    Please Login or Register  to view this content.
    Last edited by mehmetcik; 10-15-2018 at 05:26 PM.

  8. #8
    Registered User
    Join Date
    10-12-2018
    Location
    NY,USA
    MS-Off Ver
    2016
    Posts
    7

    Re: Autopopulate drop down if contains only one value

    Thanks for the quick reply,

    Ah I see, I thought the code I posted before will help with that solution I guess not. Sorry, Would you be able to guide me in the right direction?

    Thanks again.

  9. #9
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Autopopulate drop down if contains only one value

    Ok.

    Please Specify exactly which cell you change and what you expect to happen.

    Meanwhile I will try and come up with something.

    Ok lets look at H7

    When you click on that cell you are presented with a list that is created using this formula

    IF($F7= "Corporate",(OFFSET(INDIRECT("Corp[#Headers]"),MATCH($G7,INDIRECT("Corp[Juris]"),0),2,COUNTIF(INDIRECT("Corp[Juris]"),$G7),1)),(OFFSET(INDIRECT("PTP[#Headers]"),MATCH($G7,INDIRECT("PTP[Juris]"),0),2,COUNTIF(INDIRECT("PTP[Juris]"),$G7),1)))

    If you enter that same formula in K7 it will either return an entry or an error.

    If an error then proceed with the data validation

    Otherwise use the entry.


    I cannot paste the code.

    Look at the attachment
    Attached Files Attached Files
    Last edited by mehmetcik; 10-15-2018 at 06:33 PM.

  10. #10
    Registered User
    Join Date
    10-12-2018
    Location
    NY,USA
    MS-Off Ver
    2016
    Posts
    7

    Re: Autopopulate drop down if contains only one value

    Hi,

    This is literally close to what I needed! So basically I want to choose from drop down column F, then choose from drop down column G, but once I choose column G, if the validation value for column H only as one value, it will automatically populate the cell in column H.

    I just have a couple questions:
    - there seem to be a error message if I click elsewhere on the excel, should I include the "On Error Resume Next"?
    - it seem as though in order for column H to populate I will need to click on the cell for it to populate, is there a way to make it populate itself?

    Thanks again for the help, I appreciate it!

  11. #11
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Autopopulate drop down if contains only one value

    1. I stripped the macro down to its basics. You can introduce code for error checking.

    eg

    Please Login or Register  to view this content.

    You can always move the code into a normal macro.

    Insert a modified formula in all of column K so it returns an empty cell instead of an error.

    Then copy Paste values.

    You might need to reenter the Data Validation at the end of the Macro.

  12. #12
    Registered User
    Join Date
    10-12-2018
    Location
    NY,USA
    MS-Off Ver
    2016
    Posts
    7

    Re: Autopopulate drop down if contains only one value

    Hi,

    Thanks! It seem like just putting the code below helped with the error message:
    Please Login or Register  to view this content.
    Sorry I'm still new to this, so when you say a normal macro do you mean a module? If I insert the whole code into the module will that solve the issue of being able to have column H automatically update without clicking it?

    Thanks again!!!

  13. #13
    Registered User
    Join Date
    10-12-2018
    Location
    NY,USA
    MS-Off Ver
    2016
    Posts
    7

    Re: Autopopulate drop down if contains only one value

    Sorry I have another question, when I highlight a couple cells on column H, lets say H7:H10, it will automatically change the value to H7, was wondering why is that and is that the same reason why Column H only updates if its physically clicked on?

    Is there anyway to fix this situation?

    Thanks alot for your help again.

+ 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. [SOLVED] Drop down to autopopulate adjacent cell
    By PJELLIOTT in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-20-2017, 06:59 AM
  2. [SOLVED] Autopopulate macro, needs to searrch for appropriate section to autopopulate
    By Butcher1 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-09-2015, 09:11 AM
  3. Replies: 5
    Last Post: 11-01-2014, 06:00 AM
  4. Autopopulate multiple cells based on one drop down menu
    By Vincent16 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-15-2013, 04:08 PM
  5. Replies: 0
    Last Post: 01-31-2013, 12:29 PM
  6. Replies: 0
    Last Post: 04-17-2008, 05:22 PM
  7. Replies: 2
    Last Post: 10-13-2005, 09:05 AM

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