PDA

View Full Version : Deleting a Record from a Worksheet



jason_kelly
12-08-2010, 12:25 PM
Hi there,

I need your help.

I have a userform from which I would like to program the "Delete Record" button to search through 2 worksheets for the record based on the file number specified and remove the line from the specified worksheet.

Any help with this is greatly appreciated.

Thanks a bunch

Bob Phillips
12-08-2010, 12:50 PM
Private Sub btndel_Click()
Dim cell As Range

On Error Resume Next
Set cell = Worksheets("Active_Data").Columns("C").Find(Me.h3.Text)
If cell Is Nothing Then

Set cell = Worksheets("Inactive_Data").Columns("C").Find(Me.h3.Text)
End If

If Not cell Is Nothing Then

cell.EntireRow.Delete
End If
End Sub

kroz
12-09-2010, 05:41 AM
If cell Is Nothing Then

Set cell = Worksheets("Inactive_Data").Columns("C").Find(Me.h3.Text)
End If

If Not cell Is Nothing Then

cell.EntireRow.Delete
End If


Is there a special reason to use

If a
End if
if NOT a
end if

instead of

If a
else
end if

I'm a bit puzzled

Bob Phillips
12-09-2010, 06:38 AM
Yes, because it searches two worksheets, and either could set the cell object variable.

kroz
12-09-2010, 06:54 AM
oh yes, i see it now, thanx for clearing that up.