Tick checkbox depending on Listbox selection

daithiboy

Board Regular
Joined
Jul 1, 2016
Messages
77
Hi All,

I've done some searching but could not find an answer for this.

In my userform there are a couple of textboxes, a combobox, 12 checkboxes and a listbox populated with a table. I would like all of the boxes to populate when I select a line in the listbox. Using the click event, I can populate the text and comboboxes without issue, but when I try an if statement to decide whether or not to check my first checkbox I get an object required error on the first line of my if statement.

Here is my code so far:

VBA Code:
Private Sub ConsultantList_Click()

    Consultant.Value = ConsultantList.Column(0)
    Specialty.Value = ConsultantList.Column(1)
    Hospital.Value = ConsultantList.Column(2)
    
    If ConsultantList.Column(4).Value = "Yes" Then 'error occurs here on ConsultantList.Column(4).Value
        CheckBox1.Value = True
    Else
        CheckBox1.Value = False
    End If
    
End Sub

Any advice you guys can give would be very much appreciated.

Many thanks in advance,
Dave
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi,
try this update to your code

VBA Code:
Private Sub ConsultantList_Click()

    With Me.ConsultantList
        Me.Consultant.Value = .Column(0)
        Me.Specialty.Value = .Column(1)
        Me.Hospital.Value = .Column(2)
        Me.CheckBox1.Value = CBool(.Column(4) = "Yes")
    End With
    
End Sub

Dave
 
Upvote 0
What is error message? Maybe you trying to catch data from column that not exist.
 
Upvote 0
You can use listbox property "Value" only if listbox is populated manualy with items,
but if you are using "RowSource" property to populate listbox you must remove this property and
write ConsultantList.Column(4) = "Yes"
 
Upvote 0
Solution

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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