+ Reply to Thread
Results 1 to 6 of 6

If ComboBox = "" then Textbox = ""

  1. #1
    Registered User
    Join Date
    09-17-2021
    Location
    London, England
    MS-Off Ver
    365
    Posts
    8

    Question If ComboBox = "" then Textbox = ""

    Hi Everyone!

    New to the forum, Excel, VBA and Macros so please go easy on me! Iv recently started making some VBA userforms for work and iv come to enjoy the little projects Iv been working on and learn as I go along. I have been using Google/Youtube etc for most of my basic needs. My code is a mess but for the most part gets the job done.

    Iv come across an issue and iv been at it for 2 days now with little to no results so im here to ask the experts for advice. I have a client userform with around 40 Comboboxes each with 3 options (Pass,Fail,N/A). I need the userform to...

    If all Comboboxes are "Pass" or "N/A" then
    Textbox = "Pass"
    If a single Combobox is "Fail" then
    Textbox = "Fail"

    I need the textbox to update after each selection of a combobox option.

    The current Code I have been testing / messing with is as follows (below) however this updates the textbox based on the most recent combobox input.

    Private Sub ComboBox1_Change()
    If ComboBox1.value = "Fail" Then
    TextBox10.value = "Fail"
    Else
    TextBox10.value = "Pass"
    End If
    End Sub

    Hopefully this all makes sense! Any advice would be great. Thanks!

  2. #2
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: If ComboBox = "" then Textbox = ""

    The sample code you posted it only looking at your combobox1 and if you need or want to check ALL 40 to determine what to set the text box to, then you will need to have your if condition within a loop of all the boxes..

    Please Login or Register  to view this content.
    Something like this, but i havent tested this so cant guarantee it will work as is.
    If you find the suggestion or solution helpful, please consider adding reputation to the post.

  3. #3
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: If ComboBox = "" then Textbox = ""

    I need the textbox to update after each selection of a combobox option.
    This will give you an idea...

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by sintek; 09-17-2021 at 03:33 PM.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  4. #4
    Registered User
    Join Date
    09-17-2021
    Location
    London, England
    MS-Off Ver
    365
    Posts
    8

    Re: If ComboBox = "" then Textbox = ""

    Quote Originally Posted by sintek View Post
    This will give you an idea...

    Please Login or Register  to view this content.
    This was exactly what I needed and the Sample you provided was very helpful in giving me an understanding of how the code works. Very much appreciated!

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: If ComboBox = "" then Textbox = ""

    Since you talk about +/- 40 Comboboxes you would have to repeat the Change-Event +/- 40 times when you use Sintek's code.

    Therefore I would use a Class-event to store the code.
    Attached Files Attached Files
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  6. #6
    Registered User
    Join Date
    09-17-2021
    Location
    London, England
    MS-Off Ver
    365
    Posts
    8

    Re: If ComboBox = "" then Textbox = ""

    Quote Originally Posted by bakerman2 View Post
    Since you talk about +/- 40 Comboboxes you would have to repeat the Change-Event +/- 40 times when you use Sintek's code.

    Therefore I would use a Class-event to store the code.
    Oh thanks for this. Very Handy. I wasnt even aware this was an option!.. Again thank you for the Sample as it really helps to have something to look at!.. again much appreciated!

+ 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. Replies: 3
    Last Post: 11-19-2020, 08:30 PM
  2. Replies: 5
    Last Post: 02-05-2019, 12:03 AM
  3. Replies: 2
    Last Post: 07-24-2017, 02:19 AM
  4. [SOLVED] Column X-Ref list - Sheet1 Col A "pages", Col B:FL "Req" to Sheet2 ColA "req", ColB "page"
    By excel-card-pulled in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 04-07-2017, 09:30 AM
  5. = EMBED("Forms.ComboBox.1","") error "Reference not valid."
    By CatharinaCatharina in forum Excel General
    Replies: 2
    Last Post: 12-11-2014, 09:58 AM
  6. Replies: 4
    Last Post: 11-17-2013, 12:05 PM
  7. [SOLVED] How to USE """"" cells count """"" change font color
    By austin123456 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2013, 06:14 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