Hello all. I'm sure this is possible but I think I may be venturing into arrays, which I don't have a lot of understanding of. I have a listbox that populates a range of values (Strings) from a sheet. Each string value has a unique value attributed to it, however there are only a handful of string variables. The unique data value can be associated with different groups as well. For example, 2 columns (group, name) with n different groups with each group containing unique data values like below:
A B
Group1 value1
Group1 value2
Group2 value1
Group2 value2
Group3 value3
Group4 value1
Group4 value2
Group5 value1
...
The listbox shows up:
Group1
Group2
Group3
Group4
...
Right now my delete routine can select say Group2 (which then removes value1) and removes the row and moves up, however value2 remains obviously. I would like to remove all values (rows and objectively Group2 as well) associated with Group2 and move rows up as the current routine does. Since The Groups values can grow to n+1, how would vba identify that all values associated with a listbox selected group be removed? Below is my delete code to remove only one line at a time:
A B
Group1 value1
Group1 value2
Group2 value1
Group2 value2
Group3 value3
Group4 value1
Group4 value2
Group5 value1
...
The listbox shows up:
Group1
Group2
Group3
Group4
...
Right now my delete routine can select say Group2 (which then removes value1) and removes the row and moves up, however value2 remains obviously. I would like to remove all values (rows and objectively Group2 as well) associated with Group2 and move rows up as the current routine does. Since The Groups values can grow to n+1, how would vba identify that all values associated with a listbox selected group be removed? Below is my delete code to remove only one line at a time:
Code:
Private Sub cmdDelete_Click()
' Deletes items and values based on user defined selection through controls
' if deletion is made within middle of range, data is moved up
Rw = Me.ListBox1.ListIndex + 2
If Me.ListBox1.ListIndex = -1 Then
MsgBox "You haven't selected a group to delete."
ElseIf MsgBox("You are about to delete " & TextBox1.Text & _
" from the Group Distributions and ALL assoicated data with this group. Do you wish to continue?", _
vbYesNo + vbDefaultButton2, "Delete Group") = vbNo Then
Exit Sub
End If
If Me.ListBox1.ListIndex > -1 Then Sheets(msSHEET_NAME).Cells(Rw, 1).EntireRow.Delete
With ThisWorkbook.Sheets(msSHEET_NAME)
TextBox1.Text = ""
End With
FillListBox
End Sub