Userform Combobox - Put data in cells according to selection

ExtraCheese

New Member
Joined
Sep 18, 2020
Messages
12
Office Version
  1. 2016
Platform
  1. Windows
I have an userform with two Comboboxes and a textbox. Combobox1 has a string of time slots. The selection of combobox1 should define in which row the data from textbox1 is put.
Combobox2 is populated by the same text as columns B to I, the selection should define in which column the data from textbox1 is put.

I can't find the answer to my problem anywhere... is this possible in Excel?

Simplified example of how my sheet looks like:

Action
TimeTask ATask BTask CTask DTask E
22:00 - 23:00
23:00 - 0:00
0:00 - 1:00
1:00 - 2:00
2:00 - 3:00
3:00 - 4:00
4:00 - 5:00
5:00 - 6:00
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi,
you can use the ListIndex property of the controls

example

VBA Code:
Private Sub CommandButton1_Click()
    Dim RecordRow As Long, RecordColumn As Long
    
    RecordRow = Me.ComboBox1.ListIndex + 3
    RecordColumn = Me.ComboBox2.ListIndex + 2
    
    Cells(RecordRow, RecordColumn).Value = Me.TextBox1.Value
    
End Sub

This assumes the lists in the controls are in same order as your worksheet

Dave
 
Upvote 0
Solution

Forum statistics

Threads
1,215,375
Messages
6,124,578
Members
449,174
Latest member
chandan4057

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