Select the sheet from the combo box

mmn1000

Board Regular
Joined
Mar 17, 2020
Messages
76
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
Hello
I'm using the following code
VBA Code:
Private Sub ComboBox1_Change()
   Dim I As Integer
   I = Range("D" & Rows.Count).End(xlUp).Row + 1
        Me.TextBox1.Text = Cells(I, 2)
        Me.TextBox2.Text = Cells(I, 3)

    If Cells(I, 4).Value = "P" Then OptionButton4.Value = True Else OptionButton5.Value = True:

End Sub
VBA Code:
Private Sub CommandButton1_Click()
   Dim I As Integer
   I = Range("D" & Rows.Count).End(xlUp).Row + 1
    If TextBox2 <> "" Then
       

       Worksheets(ComboBox1.Value).Select
       
        Worksheets(ComboBox1.Value).Range("E" & I).Value = TextBox4.Value
        If OptionButton4.Value = True Then Cells(I, 4) = "P" Else Cells(I, 4) = "O"
         

            MsgBox "The information was successfully recorded", vbMsgBoxRight, "submit information"
            
        Else
        
            MsgBox "Complete the text box", vbMsgBoxRight, "submit information"
    End If
        I = Range("D" & Rows.Count).End(xlUp).Row + 1
        Me.TextBox1.Text = Cells(I, 2)
        Me.TextBox2.Text = Cells(I, 3)
End Sub

VBA Code:
Private Sub UserForm_Activate()
'    OptionButton1 = True
     For I = 1 To Sheets.Count
        ComboBox1.AddItem Sheets(I).Name
    Next I

End Sub
I enter the information in the sheet
In the sheet that I select from the combo box
I have a small problem with this code
Is it possible that with this code, the same sheet will be displayed when selecting the name of the sheet from the Cambodian box on the Excel page?
For this reason, I stated that when I want to perform the registration operation for other sheets, it takes into account the active sheet position in Excel, which is the first sheet, and then registers it in the desired sheet, which causes an error. Please attach the file. Check
 
Last edited by a moderator:

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,214,652
Messages
6,120,747
Members
448,989
Latest member
mariah3

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