I have a "Data" worksheet that I want users to be able to edit the data in this worksheet by using a Form (keep the data uniform). When the user opens the initial form (UserForm1), this will display all of the rows of data that they can select from to edit. Because this data set is large (will be 6,000 rows of data), I have included textboxes in the form so they can filter down to the data they want to edit. The textboxes filter the "Data" worksheet, but my listbox doesn't show the "live" filtered version as the user uses the textboxes. Below is the code I am using to add the data to the Listbox and the GetRange function (I will attach a copy of the spreadsheet also). I know excel has the .SpecialCells(xlCellTypeVisible), but I cannot figure out how to use this to show the filtered data. I'm using the .RowSource = rg.Address(external:=True), to add the data to the listbox.
I have seen people use the .AddItem and loop through the data using the .List creating an array list, but that seems to be slow, cannot add more than 10 columns, and I cannot use multiple textboxes to filter at the same time unless the user types and then selects a button which uses all of the textbox data.
Private Sub UserForm_Activate()
Call AddDataToListBox
End Sub
Private Sub AddDataToListBox()
Dim rg As Range
Set rg = GetRange()
'Link the data to the ListBox
With ListBox_SelectDataToEdit
.RowSource = rg.Address(external:=True)
.ColumnCount = 12
.ColumnWidths = "55;210;210;0;120;55;40;45;45;60;55;40"
.ColumnHeads = True
.ListIndex = 0
End With
End Sub
Function GetRange() As Range
Set sh = ThisWorkbook.Sheets("Data")
Set GetRange = sh.Range("B5:N3000")
Set GetRange = GetRange.Offset(1, 0).Resize(GetRange.Rows.Count - 1)
End Function
Please let me know if I was unclear on anything or if you need a better explanation.
Thank you!!
I have seen people use the .AddItem and loop through the data using the .List creating an array list, but that seems to be slow, cannot add more than 10 columns, and I cannot use multiple textboxes to filter at the same time unless the user types and then selects a button which uses all of the textbox data.
Private Sub UserForm_Activate()
Call AddDataToListBox
End Sub
Private Sub AddDataToListBox()
Dim rg As Range
Set rg = GetRange()
'Link the data to the ListBox
With ListBox_SelectDataToEdit
.RowSource = rg.Address(external:=True)
.ColumnCount = 12
.ColumnWidths = "55;210;210;0;120;55;40;45;45;60;55;40"
.ColumnHeads = True
.ListIndex = 0
End With
End Sub
Function GetRange() As Range
Set sh = ThisWorkbook.Sheets("Data")
Set GetRange = sh.Range("B5:N3000")
Set GetRange = GetRange.Offset(1, 0).Resize(GetRange.Rows.Count - 1)
End Function
Please let me know if I was unclear on anything or if you need a better explanation.
Thank you!!