I am using Active X ComboBox in worksheet in ComboBox1 i have listed the sheets name thats working fine.
I triying to add the data in ComboBox2 based on the sheet seleted in ComboBox1.
If i select the sheet name in ComboBox1 from dropdown list then automatically ComboBox2 needs to be fill the data from selected sheet and once i click the command button the sheet in ComboBox1 and details in ComboBox2 needs to select at the same time.Please help me on this topic it will more helpfull for me to develope my project.
Simply my qustion is i need to select the worksheet in ComboBox1 and need to select the ranges in ComboBox2 once i click the command button the specific sheet and ranges needs to select at a time.
Code below:
Private Sub CommandButton1_Click()
Dim sName As String
Dim x As Integer
Dim Range As Range
Dim Sh As Worksheet
For x = 3 To Sheets.Count
Sheets(x).Visible = False
Next x
sName = ComboBox1.Value
With ActiveWorkbook.Sheets(sName)
.Visible = True
.Activate
End With
End Sub
Private Sub Worksheet_Activate()
Dim Sh As Worksheet
Dim sName As String
Dim x As Integer
Me.ComboBox1.Clear
For Each Sh In ThisWorkbook.Worksheets
Me.ComboBox1.AddItem Sh.Name
Next Sh
Exit Sub
End Sub
Private Sub ComboBox2_Change()
Dim Sh As Worksheet
Dim sName As String
sName = ComboBox1.Value
If ComboBox1.Value Then
Sheets(sName).Activate
Set Sh = Worksheets("sName")
If ActiveSheet.Name = Sh.Name Then
ComboBox2.ListFillRange = "sName"
Else
Exit Sub
End If
End Sub