ganesh_r1988
New Member
- Joined
- Mar 12, 2019
- Messages
- 3
Hi,
Currently I am into a project where I was stucked writing code for the below mentioned activity.
I have created an userform with a multiselect Listbox and a Command Button
ListBox populate the Items from a Table Source with 2 Columns.
[TABLE="width: 129"]
<tbody>[TR]
[TD]Zone[/TD]
[TD]Region[/TD]
[/TR]
[TR]
[TD]North[/TD]
[TD]N1[/TD]
[/TR]
[TR]
[TD]North[/TD]
[TD]N2[/TD]
[/TR]
[TR]
[TD]North[/TD]
[TD]N3[/TD]
[/TR]
[TR]
[TD]North[/TD]
[TD]N4[/TD]
[/TR]
[TR]
[TD]South[/TD]
[TD]S1[/TD]
[/TR]
[TR]
[TD]South[/TD]
[TD]S2[/TD]
[/TR]
[TR]
[TD]South[/TD]
[TD]S3[/TD]
[/TR]
[TR]
[TD]South[/TD]
[TD]S4[/TD]
[/TR]
[TR]
[TD]East[/TD]
[TD]E1[/TD]
[/TR]
[TR]
[TD]East[/TD]
[TD]E2[/TD]
[/TR]
</tbody>[/TABLE]
Command Button is for Deleting the Items Selected in the Listbox.
Now Once I click the Delete Command Button , the selected rows should get deleted in the Original Table Source.
For this I have written the below code, But the issue I am facing is even when I select 2 or more rows in the listbox , only the Last Selected Row is getting deleted.
Click the below link to download the working file.
https://drive.google.com/open?id=1P5wiW6WVFAVQBgixPuA7gqyacR1aktvi
Please help me out in this regard.
Thanks in Advance
Regards,
Ganesh.
[TABLE="width: 129"]
<tbody>[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Currently I am into a project where I was stucked writing code for the below mentioned activity.
I have created an userform with a multiselect Listbox and a Command Button
ListBox populate the Items from a Table Source with 2 Columns.
[TABLE="width: 129"]
<tbody>[TR]
[TD]Zone[/TD]
[TD]Region[/TD]
[/TR]
[TR]
[TD]North[/TD]
[TD]N1[/TD]
[/TR]
[TR]
[TD]North[/TD]
[TD]N2[/TD]
[/TR]
[TR]
[TD]North[/TD]
[TD]N3[/TD]
[/TR]
[TR]
[TD]North[/TD]
[TD]N4[/TD]
[/TR]
[TR]
[TD]South[/TD]
[TD]S1[/TD]
[/TR]
[TR]
[TD]South[/TD]
[TD]S2[/TD]
[/TR]
[TR]
[TD]South[/TD]
[TD]S3[/TD]
[/TR]
[TR]
[TD]South[/TD]
[TD]S4[/TD]
[/TR]
[TR]
[TD]East[/TD]
[TD]E1[/TD]
[/TR]
[TR]
[TD]East[/TD]
[TD]E2[/TD]
[/TR]
</tbody>[/TABLE]
Command Button is for Deleting the Items Selected in the Listbox.
Now Once I click the Delete Command Button , the selected rows should get deleted in the Original Table Source.
For this I have written the below code, But the issue I am facing is even when I select 2 or more rows in the listbox , only the Last Selected Row is getting deleted.
Code:
Private Sub Cmd_Del_Click()
Dim sh As Worksheet
Set sh = ThisWorkbook.Worksheets("Sheet1")
Dim i As Long
For i = Me.LB_ZoneRegion.ListCount - 1 To 0 Step -1
If Me.LB_ZoneRegion.Selected(i) = True Then
sh.Range("A" & i + 2 & ":B" & i + 2).Select
Selection.Delete
End If
Next i
Call UserForm_Initialize
End Sub
------------------------------------------------------------------------
Private Sub UserForm_Initialize()
On Error Resume Next
With Me.LB_ZoneRegion
.Clear
.ColumnCount = 2
.ColumnHeads = True
.ColumnWidths = "40;50"
.RowSource = "ZoneRegion"
.MultiSelect = fmMultiSelectMulti
End With
End Sub
Click the below link to download the working file.
https://drive.google.com/open?id=1P5wiW6WVFAVQBgixPuA7gqyacR1aktvi
Please help me out in this regard.
Thanks in Advance
Regards,
Ganesh.
[TABLE="width: 129"]
<tbody>[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]