Selecting any single value in any column in a multicolumn combobox

chazrab

Well-known Member
Joined
Oct 21, 2006
Messages
912
Office Version
  1. 365
Platform
  1. Windows
This code only selects the value on the selected row of the first column
Code:
Private Sub CommandButton1_Click()
TextBox1.Value = ComboBox1.Value
End Sub
If I click on any book in any column the button code should put that clicked book value in Textbox1 - not the first value on that row, which is what its doing.
I'm sure this has come up at some point before. chatGPT does a poor job of helping, just copying code from Stackoverflow.
Image best explains dilemma. Seems doable.
Thanks for anyone's help.
cr


ALWAYS ONLY SELECTS VALUE ON SELECTED ROW IN FIRST COLUMN.  NEED TO BE ABLE TO SELECT ANY VALU...png
 
@chazrab
Just an idea, instead of a ListBox, why not use multiple checkboxes?
You want to use a multi-column ListBox to select item on one column. When a user selects an item in a ListBox, it usually means selecting the entire row, and visually, we can see the blue highlight on the entire row. So, in my opinion, what you're attempting to do is somewhat counter intuitive. Additionally, if you wish, you can set up the checkboxes at runtime via code, so you don't have to configure them manually.
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
@chazrab
Just an idea, instead of a ListBox, why not use multiple checkboxes?
You want to use a multi-column ListBox to select item on one column. When a user selects an item in a ListBox, it usually means selecting the entire row, and visually, we can see the blue highlight on the entire row. So, in my opinion, what you're attempting to do is somewhat counter intuitive. Additionally, if you wish, you can set up the checkboxes at runtime via code, so you don't have to configure them manually.
I have no idea what you mean by 'Additionally, if you wish, you can set up the checkboxes at runtime via code, so you don't have to configure them manually.' - Checkboxes would be OK if it can accomplish the ultimate goal. I put the compbbox then listbox idea out there as an alternative to
eliminating typing the same code for 66 unique labels - the user clicks on any label teh BIBLEBOOKS userfrom and it immediately puts that label name in Textboz1, opens the BOOKCHAPTER userfrom, user clicks on any number from 1 to 80, puts a single space followed by that value followed by a colon,
which immediately opens the CHAPTERVVERSE userfrom, the user clicks on any verse number and it immediately completes the Biblical reference in
Textbox1 and runs a macro which displays that exact Bible reference - sound complicated ? its really not at all - just having to type the same exact lines
many many times. I am sorry for this long explanation to achieve this simple result:

To cut down and/or eliminate redundant repetitive code lines, I tried playing around with
Code:
If Activecontrol.Name = "Matt" Then
  Textbox1.value = "Matthew"
   BOOKCHAPTER.Show (and same code lines for this label, etc.
Else
If If Activecontrol.Name = "Mark" Then
etc., for every one of the 66 BIBLEBOOK labels.
but Excel said, "Nope, you can't do that"
so I spend 8+ hours in a full day typing much of the same code,
all the while thinking 'there must be an easier, simpler way to do this'

After tryiing a Combobox then Listbox idea, Domenic was helpful in his code but I'm still struggling with
getting this to work right. And by 'work right' i mean the result in ine second image.- in which the user does not have to put one finger on the keyboard - only a series of 3 mouseclicks and bam! - up displays that exact vers in large Textboq. IT goes further - I have to do this for not
one - but 4 textboxes - as seen in the 3rd image

You may not recall who I am - you helped me with the beginning stages of this project 3 years ago and it has evolved into what these
images show. There's a limit to my VBA coding experience but I feel certain there's a shorter more simple way to achieve the goals
in the images below.

I took way too long to explain this - sorry

cr :)
 

Attachments

  • LOTS OF THE SAME CODE LINES TYPED 66, 80 AND 80 TIMES.png
    LOTS OF THE SAME CODE LINES TYPED 66, 80 AND 80 TIMES.png
    204 KB · Views: 6
  • THE RESULT.  USER DOES NOT HAVE TO TYPE ANYTHING - JUST 3 MOUSECLICKS - FAST AND ELIINATES HUM...png
    THE RESULT. USER DOES NOT HAVE TO TYPE ANYTHING - JUST 3 MOUSECLICKS - FAST AND ELIINATES HUM...png
    20.2 KB · Views: 5
  • Screenshot 2024-04-20 021942.png
    Screenshot 2024-04-20 021942.png
    202 KB · Views: 6
Upvote 0
There's many typos - but the time limit to edit expired - I type too fast. '
cr
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,930
Members
452,367
Latest member
TePunaBloke

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