Code to select drop down entry based on other field selection

Paul15

New Member
Joined
Jun 25, 2020
Messages
44
Office Version
  1. 2019
Platform
  1. Windows
Dear forum,

I have a workbook with a data entry form. I have VBA to place certain text and colours into fields based upon certain selections in other fields. I am looking to expand this as follows:

If in my cboPort field "house" is selected from the drop down then I wish my cboVess to auto populate to "train"

I guess it will be a simple If, Then statement but cant seem to get it

Regards

Paul
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Glad to hear you have managed to get things working.

Do you mind posting about your solution? Then it is perfectly fine to mark your post as the solution to help future readers. Otherwise, please do not mark a post that doesn't contain a solution.
 
Upvote 0
Hi, thanks to smozgur for reminding me to share my fix for my question. I have changed values to protect what I'm doing but the result is the same. I wanted to auto populate certain fiends on my input for based upon other field selection. therefore saving a user from having to do more data input than was necessary. Always out for an easy life. The pribcilpe being, if a person is in a certain type accommodation, then my cbo.Vess will auto populate with the required result, saving this having to be selected.

hope this can be of use and regards




VBA Code:
Private Sub Port_Change()

Dim IsLocked           As Boolean
    Dim Destination       As Variant

    Destination = Array("house", "hotel", "b&b")

    IsLocked = Not IsError(Application.Match(Me.Port.Text, Destination, 0))



'automatically selects building

    With Me.cboVess
        .Locked = IsLocked
        .Text = IIf(.Locked, "building", "")
    End With
    
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,918
Messages
6,122,249
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top