Combobox VBA

Ivan_Pzdorvan

New Member
Joined
Mar 3, 2023
Messages
4
Office Version
  1. 2013
Platform
  1. Windows
1234
Ivan
Jon
Stiven
?​
Lex
I have 3 combobox. Name= А, Day= В
combobox1=3
combobox2=Stiven
write x in cell (combobox1,combobox2)
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Welcome to the MrExcel forum. Please accept my warmest greetings and sincere hope that all is well.

To try to solve your doubt. I present you with two options, the first, if both comboboxes are inside a userform.
The second option is if the comboboxes are activex controls and are on the sheet.

In the options, change the code "sheet1" to the name of your sheet where you have the data.

Option 1.
If your data is like this in your sheet, that is, starting in column A and row 1:

Dante Amor
ABCDEF
11234
2Ivan
3Jon
4StivenX
5Lex
6
7
sheet1


The following code inside the userform:
VBA Code:
Option Explicit

Private Sub ComboBox1_Change()
  Call ponerX
End Sub

Private Sub ComboBox2_Change()
  Call ponerX
End Sub

Sub ponerX()
  If ComboBox1.ListIndex > -1 And ComboBox2.ListIndex > -1 Then
    Sheets("sheet1").Cells(ComboBox1.ListIndex + 2, ComboBox1.ListIndex + 2).Value = "X"
  End If
End Sub

Private Sub UserForm_Activate()
  With Sheets("sheet1")
    ComboBox1.List = .Range("A2", .Range("A" & Rows.Count).End(3)).Value
    ComboBox2.List = Application.Transpose(.Range("B1", .Cells(1, Columns.Count).End(1)).Value)
  End With
End Sub

Option 2.
If the comboboxes are activex controls and are on the sheet.

The following code in the events of the sheet that has the information and the combos
VBA Code:
Private Sub ComboBox1_Change()
  Call fillx
End Sub

Private Sub ComboBox2_Change()
  Call fillx
End Sub

Sub fillx()
  Dim f As Range
  Dim nRow As Long
 
  With Sheets("sheet1")
    If ComboBox1.ListIndex > -1 And ComboBox2.ListIndex > -1 Then
      Set f = Range("A:A").Find(ComboBox1.Value, , xlValues, xlWhole, , , False)
      If Not f Is Nothing Then
        nRow = f.Row
        Set f = Range("1:1").Find(ComboBox2.Value, , xlValues, xlWhole, , , False)
        If Not f Is Nothing Then
          .Cells(nRow, f.Column).Value = "X"
        End If
      End If
    End If
  End With
End Sub

Note:
If you have difficulties, please provide all the necessary information to help you: sheet name, combo names, if they are activex or in a userform, where is the data in your sheet and how do you load the data into the combos.

I hope the above helps you.
Respectfully
Dante Amor
 
Last edited:
Upvote 0
Welcome to the MrExcel forum. Please accept my warmest greetings and sincere hope that all is well.

To try to solve your doubt. I present you with two options, the first, if both comboboxes are inside a userform.
The second option is if the comboboxes are activex controls and are on the sheet.

In the options, change the code "sheet1" to the name of your sheet where you have the data.

Option 1.
If your data is like this in your sheet, that is, starting in column A and row 1:

Dante Amor
ABCDEF
11234
2Ivan
3Jon
4StivenX
5Lex
6
7
sheet1


The following code inside the userform:
VBA Code:
Option Explicit

Private Sub ComboBox1_Change()
  Call ponerX
End Sub

Private Sub ComboBox2_Change()
  Call ponerX
End Sub

Sub ponerX()
  If ComboBox1.ListIndex > -1 And ComboBox2.ListIndex > -1 Then
    Sheets("sheet1").Cells(ComboBox1.ListIndex + 2, ComboBox1.ListIndex + 2).Value = "X"
  End If
End Sub

Private Sub UserForm_Activate()
  With Sheets("sheet1")
    ComboBox1.List = .Range("A2", .Range("A" & Rows.Count).End(3)).Value
    ComboBox2.List = Application.Transpose(.Range("B1", .Cells(1, Columns.Count).End(1)).Value)
  End With
End Sub

Option 2.
If the comboboxes are activex controls and are on the sheet.

The following code in the events of the sheet that has the information and the combos
VBA Code:
Private Sub ComboBox1_Change()
  Call fillx
End Sub

Private Sub ComboBox2_Change()
  Call fillx
End Sub

Sub fillx()
  Dim f As Range
  Dim nRow As Long
 
  With Sheets("sheet1")
    If ComboBox1.ListIndex > -1 And ComboBox2.ListIndex > -1 Then
      Set f = Range("A:A").Find(ComboBox1.Value, , xlValues, xlWhole, , , False)
      If Not f Is Nothing Then
        nRow = f.Row
        Set f = Range("1:1").Find(ComboBox2.Value, , xlValues, xlWhole, , , False)
        If Not f Is Nothing Then
          .Cells(nRow, f.Column).Value = "X"
        End If
      End If
    End If
  End With
End Sub

Note:
If you have difficulties, please provide all the necessary information to help you: sheet name, combo names, if they are activex or in a userform, where is the data in your sheet and how do you load the data into the combos.

I hope the above helps you.
Respectfully
Dante Amor
1677872067414.png

1677872231024.png

1677872264660.png

Місяць = sheet
День = В2:AF2
0,1,2,3,4,5,6 = A3:A24
in VBA
if День = 15 and 0 = Гулич when click buttom must P7 = X
sheet(combobox1.Value)
 
Upvote 0
Please, update the names of the comboboxes in the following code. Combobox1 for the sheet names, Combobox2 for days 1-31, and Combobox3 for the data you have in column A.
You can identify them by colors:
Rich (BB code):
Private Sub CommandButton1_Click()
  Dim sh As Worksheet
  Dim f As Range
  Dim col As Long
  
  If ComboBox1.ListIndex > -1 And ComboBox2.ListIndex > -1 And ComboBox3.ListIndex > -1 Then
  
    Set sh = Sheets(ComboBox1.Value)                                        'sheet
    Set f = sh.Range("B2:AF2").Find(ComboBox2.Value, , xlValues, xlWhole)   '1 to 31
    If Not f Is Nothing Then
      col = f.Column
      Set f = sh.Range("A:A").Find(ComboBox3.Value, , xlValues, xlWhole)   'data in column A
      If Not f Is Nothing Then
        sh.Cells(f.Row, col).Value = "X"
      End If
    End If
  End If
End Sub

Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
 
Upvote 0
Solution
Please, update the names of the comboboxes in the following code. Combobox1 for the sheet names, Combobox2 for days 1-31, and Combobox3 for the data you have in column A.
You can identify them by colors:
Rich (BB code):
Private Sub CommandButton1_Click()
  Dim sh As Worksheet
  Dim f As Range
  Dim col As Long
 
  If ComboBox1.ListIndex > -1 And ComboBox2.ListIndex > -1 And ComboBox3.ListIndex > -1 Then
 
    Set sh = Sheets(ComboBox1.Value)                                        'sheet
    Set f = sh.Range("B2:AF2").Find(ComboBox2.Value, , xlValues, xlWhole)   '1 to 31
    If Not f Is Nothing Then
      col = f.Column
      Set f = sh.Range("A:A").Find(ComboBox3.Value, , xlValues, xlWhole)   'data in column A
      If Not f Is Nothing Then
        sh.Cells(f.Row, col).Value = "X"
      End If
    End If
  End If
End Sub

Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
It's incredible. Everything is working. Thank you very much for your help
 
Upvote 1

Forum statistics

Threads
1,215,514
Messages
6,125,265
Members
449,219
Latest member
daynle

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