Deleting entire row.... final question

P

Pam Field

Thanks again to anyone who has helped me with this spreadsheet so far. I'm
sure this will be my last question.

I have created a spreadsheet with a command button that leads to a form to
remove a child from the spreadsheet. I have most of it working but cannot
work out how to delete the whole row of info re the child - my macro only
deletes the cell with the child's name in it and moves everything in that
column up.

Excuse the clumsiness of the code as I am a learner:

Private Sub cmdRemChild_Click()
Dim myCell As Range
Dim ChosenName As String
Dim NameFound As Boolean
Dim YesNo As Integer

ChosenName = cboChildName.Text

If Len(ChosenName) = 0 Then
MsgBox ("Please Select or Enter A Name")
cboChildName.SetFocus
Exit Sub
End If

Sheets("Child Records").Select

NameFound = False
For Each myCell In Range("Name_of_Child")
If myCell.Value = ChosenName Then
myCell.Select
NameFound = True
YesNo = MsgBox("Are you sure you want to remove this child?",
vbYesNo + vbExclamation, "Caution")

Select Case YesNo
Case vbYes
Selection.Delete Shift:=xlUp
Range("A6").Select

Case vbNo
Range("A6").Select
End Select
Unload Me
Exit For
End If
Next myCell

If NameFound = False Then
MsgBox "Name not Found!"
cboChildName.SetFocus
Exit Sub
End If

End Sub

Your help would be greatly appreciated.
Kind Regards
Pam
 
C

Chris Lavender

Hi Pam

You need to replace

Selection.Delete Shift:=xlUp

with

Selection.EntireRow.Delete

Best rgds
Chris Lav
 
P

Pam Field

Thanks so much Chris,

I figured it wouldn't be too difficult but I just couldn't work it out.

Have a lovely weekend
Pam
 
D

Don Guillett

a bit simpler

Sub deletechildrow()
Rows(Range("nameofchild").Find("a").Row).Delete
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top