Hi everyone again,
I have this code to display in the listbox and update it if necessary. Now, I added a command button with a code to delete the selected item in the ListBox, but there is a "Compile Error: Method or data member not found".
Please note that the source of the listbox with a range name "FilterFR1st" is from other sheets which filtered from the raw source sheet. This is due to filtering for specific ID. Raw source worksheets name is "FR1st".
Code where Compile Error appears
ListBox1.ListFillRange = "a:a"
Code for command button "Delete"
Private Sub DelFR1st_Click()
Dim indexi As Long
Dim answer As Integer
answer = MsgBox("Are you sure you want to remove/delete this item?", vbYesNo, "")
If answer = vbYes Then
indexi = ListBox1.ListIndex + 1
If indexi <> -1 Then
Worksheets("FR1st").Rows(indexi).EntireRow.Delete
ListBox1.ListFillRange = "a:a"
End If
Else
End If
End Sub
Display More
Whole code of my UserForm:
Option Explicit
Dim rData
Dim oCtl As MSForms.Control
Dim iX As Integer
Private Sub SaveFR1st_Click()
With Me
For Each oCtl In .Controls
If TypeName(oCtl) = "TextBox" And IsNumeric(oCtl.Tag) Then
iX = oCtl.Tag
Sheets("FR1st").Cells(Me.ListBox1.ListIndex + 2, iX) = oCtl.Value
Sheets("FR1st").Cells(Me.ListBox1.ListIndex + 2, 6) = TextBox34.Value
End If
Next oCtl
End With
LoadData
End Sub
Private Sub ListBox1_Click()
With Me
For Each oCtl In .Controls
If TypeName(oCtl) = "TextBox" And IsNumeric(oCtl.Tag) Then
iX = oCtl.Tag
oCtl.Value = .ListBox1.List(.ListBox1.ListIndex, iX - 1)
End If
Next oCtl
End With
End Sub
Private Sub UserForm_Initialize()
LoadData
End Sub
Sub LoadData()
Set rData = [FilterFR1st]
TextBox34.Value = Format(Date, "mm/dd/yyyy")
With Me.ListBox1
.ColumnCount = 6
.ColumnWidths = "0;83;100;95;90;0"
.List = rData.Value
End With
End Sub
Private Sub CloseFR1st_Click()
Unload Me
End Sub
Private Sub DelFR1st_Click()
Dim indexi As Long
Dim answer As Integer
answer = MsgBox("Are you sure you want to remove/delete this item?", vbYesNo, "")
If answer = vbYes Then
indexi = ListBox1.ListIndex + 1
If indexi <> -1 Then
Worksheets("FR1st").Rows(indexi).EntireRow.Delete
ListBox1.ListFillRange = "a:a"
End If
Else
End If
End Sub
Display More
Hope i explain it clearly...
What is the code to delete the entire row from raw source sheet with the selected item in the ListBox? I want also an Auto Refresh from the ListBox after deleting the record..
Thank you in advance.