✅ 1. CheckBox1_Click Event
What it does:
-
When CheckBox1 is checked:
-
It unchecks CheckBox2 and CheckBox3.
-
Clears TextBox1 (removes any search text).
-
Calls
LoadListBox ""
with an empty search term, which reloads data from Sheet1 (as set inLoadListBox
). ✅ 2. CheckBox2_Click Event
What it does:
-
When CheckBox2 is checked:
-
It unchecks CheckBox1 and CheckBox3.
-
Clears TextBox1.
-
Calls
LoadListBox ""
to reload data from Sheet2.
-
✅ 3. CheckBox3_Click Event
What it does:
-
When CheckBox3 is checked:
-
Unchecks CheckBox1 and CheckBox2.
-
Clears TextBox1.
-
Loads data from Sheet3.
✅ 4. TextBox1_Change Event
What it does:
-
As the user types in the TextBox1, this event triggers and:
-
Passes the search text to the
LoadListBox
function to filter data in the list box.
-
✅ 5. UserForm_Initialize Event
What it does when the form loads:
-
Sets the ListBox1 to have 10 columns.
-
Loads the list box with no search filter (initial data from Sheet3).
-
Checks CheckBox3 by default.
✅ 6. LoadListBox(SearchTerm As String) Sub
Purpose:
-
Dynamically loads and filters data from the appropriate worksheet (Sheet1, Sheet2, or Sheet3) into ListBox1.
Step-by-step breakdown:
-
Determine the active sheet based on which checkbox is selected.
-
Find the last row with data in column A.
-
Clear the ListBox to remove previous data.
-
Set column headers in the first row of ListBox1.
-
Loop through rows (starting from row 2):
-
If
SearchTerm
is blank or matches any part of the customer name (column A), it:-
Reads all 10 columns.
-
Adds the data to ListBox1.
-
-
Know more about InStr click here
-
Add matching data to ListBox1.
✅ Summary of Features:
-
-
A searchable list of customer data (from Sheet1/2/3) based on checkboxes.
-
A dynamic ListBox showing 10 columns with headers.
-
Search functionality via TextBox.
-
Mutually exclusive checkboxes to choose the source sheet.
- Click here to download the practice file
-
No comments:
Post a Comment