Dear mr / mrs,
I get run-time error 1004 when I try to delete data with cmdDelete see below the VBA
Rowsource listbox1 = information
please help me to resolve this issue
thank you in advance for your support
Kirana
Private Sub ListBox1_Click()
Dim say As Long, A As Byte, r As Long
Dinfo1 = ListBox1.List(ListBox1.ListIndex, 0)
For A = 1 To 6
Controls("Info" & A) = ListBox1.List(ListBox1.ListIndex, A - 1)
Next
Sheets("Data").Range("A:A").Find(ListBox1.Text).Activate
say = ActiveCell.Row
Sheets("Data").Range("A" & say & ":I" & say).Select
TextBox1 = ListBox1.ListIndex + 1
End Sub
Private Sub cmdDelete_Click()
Dim findvalue As Range
Dim cDelete As VbMsgBoxResult
Dim cNum As Integer
'check for values
If Info1.Value = "" Or Info2.Value = "" Then
MsgBox "There is not data to delete"
Exit Sub
End If
'give the user a chance to change their mind
cDelete = MsgBox("Are you sure that you want to delete Select Data", vbYesNo + vbDefaultButton2, "Are you sure????")
If cDelete = vbYes Then
'delete the row
Set findvalue = Sheet1.Range("B:B").Find(What:=Info2, LookIn:=xlValues)
findvalue.EntireRow.Delete
End If
'clear the controls
cNum = 6
For X = 1 To cNum
Me.Controls("Info" & X).Value = ""
Next
'refresh the listbox
Unload Me
frmaddress.Show
End Sub
Bookmarks