Hi SR. SudhirRaj, I'm Femi and I'd be happy to help you with your question. Kindly follow the steps below to do that: Open the Visual Basic for Applications (VBA) editor by pressing Alt+F11 in Excel. Insert a new UserForm by right-clicking on your workbook's name in the Project Explorer window, selecting "Insert," and then choosing "UserForm." Design your UserForm with the necessary input fields and a DropDown menu. For this example, let's assume you have a TextBox control named "txtData" for entering data and a DropDown control named "ddlSheets" for selecting the sheet. In the UserForm module, add the following code: Private Sub UserForm_Initialize() ' Initialize the UserForm ' Populate the DropDown menu with sheet names excluding specific sheets
Dim ws As Worksheet Dim excludedSheets As Variant excludedSheets = Array("Master", "Results", "Help")
' Clear previous items from the DropDown menu ddlSheets.Clear
' Add sheet names to the DropDown menu For Each ws In ThisWorkbook.Worksheets If Not IsInArray(ws. Name, excludedSheets) Then ddlSheets.AddItem ws. Name End If Next ws
' Set the default selection for the DropDown menu ddlSheets.Value = ddlSheets.List(0) End Sub
Private Sub cmdAppendData_Click() ' Append data to the selected sheet
Dim selectedSheet As Worksheet Dim rowData As Range
' Get the selected sheet Set selectedSheet = ThisWorkbook.Worksheets(ddlSheets.Value)
' Find the first empty row in the selected sheet Set rowData = selectedSheet.Cells(selectedSheet.Rows.Count, 1). End(xlUp). Offset(1)
' Append the data to the selected sheet rowData.Value = txtData.Value
' Clear the input field txtData.Value = ""
' Close the UserForm Unload Me End Sub
Private Function IsInArray(val As Variant, arr As Variant) As Boolean ' Check if a value is in the array
Dim element As Variant On Error GoTo ErrorHandler
For Each element In arr If element = val Then IsInArray = True Exit Function End If Next element
ErrorHandler: On Error GoTo 0 IsInArray = False End Function
Close the VBA editor and return to the Excel worksheet. Insert a button or a macro that opens the UserForm. You can add a button to the worksheet and assign it the following macro: Sub ShowMyUserForm() UserForm1.Show End Sub
Now, when you click the button, the UserForm will appear with a DropDown menu populated with the names of all sheets in the workbook (excluding "Master", "Results", and "Help"). After selecting a sheet from the DropDown menu and entering data in the TextBox control, clicking the "Append Data" button will append the entered data to the selected sheet in the first empty row. Kindly ensure you save your workbook as a macro-enabled file format (e.g., .xlsm) to preserve the VBA code.
Hope this helps!
Best Regards, Femi