I have a VBA form with various choices, including drop-down lists, text fields, check boxes, and radio stations.
I just wanted to learn about the best way to clear all of these fields with the click of a button. My friend tried to help by sending me the code below, but unfortunately it does not work, I checked the variable names.
Any tips on how I can improve it?
Thanks in advance.
Private Sub btnReset_Click() Unload Me UserForm.Show End Sub
Here is another code for a custom form.
Dim DeptCode 'Holds department code Private Sub UserForm_Initialize() Dim c_deptCode As Range Dim c_deptName As Range Dim deptCodes As Variant Dim deptNames As Variant Dim ws_dept As Worksheet Set ws_dept = Worksheets("lookupDept") ' Assign each range to an array containing the values deptCodes = Choose(1, ws_dept.Range("deptCode")) deptNames = Choose(1, ws_dept.Range("deptName")) For i = 1 To ws_dept.Range("deptCode").Rows.Count ' Create the combined name (code + space + name) CombinedName = deptCodes(i, 1) & " - " & deptNames(i, 1) cbo_deptCode.AddItem CombinedName Next i End Sub
source share