Tick checkbox depending on Listbox selection

daithiboy

Board Regular
Joined
Jul 1, 2016
Messages
72
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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
6,523
Office Version
  1. 2019
Platform
  1. Windows
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
 

EXCEL MAX

Active Member
Joined
Nov 11, 2020
Messages
392
Office Version
  1. 2016
Platform
  1. Windows
What is error message? Maybe you trying to catch data from column that not exist.
 

EXCEL MAX

Active Member
Joined
Nov 11, 2020
Messages
392
Office Version
  1. 2016
Platform
  1. Windows
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"
 
Solution

Watch MrExcel Video

Forum statistics

Threads
1,130,163
Messages
5,640,515
Members
417,149
Latest member
drbro

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
Top