PC Review


Reply
Thread Tools Rate Thread

Deleting entire row.... final question

 
 
Pam Field
Guest
Posts: n/a
 
      22nd Jul 2006
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


 
Reply With Quote
 
 
 
 
Chris Lavender
Guest
Posts: n/a
 
      22nd Jul 2006
Hi Pam

You need to replace

Selection.Delete Shift:=xlUp

with

Selection.EntireRow.Delete

Best rgds
Chris Lav

"Pam Field" <(E-Mail Removed)> wrote in message
news:44c1f4e0$(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Pam Field
Guest
Posts: n/a
 
      22nd Jul 2006
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

"Chris Lavender" <(E-Mail Removed)> wrote in message
news:eG7ti%(E-Mail Removed)...
> Hi Pam
>
> You need to replace
>
> Selection.Delete Shift:=xlUp
>
> with
>
> Selection.EntireRow.Delete
>
> Best rgds
> Chris Lav
>



 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      23rd Jul 2006
a bit simpler

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

--
Don Guillett
SalesAid Software
(E-Mail Removed)
"Pam Field" <(E-Mail Removed)> wrote in message
news:44c1f4e0$(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I delete merged cells in Excel without deleting the final d aries68mc Microsoft Excel Misc 5 16th Mar 2010 04:42 PM
Deleting entire row daisy2008 Microsoft Excel Programming 6 9th Dec 2008 09:19 PM
Deleting Entire Page =?Utf-8?B?RGFubyBPJ0Q=?= Microsoft Word Document Management 4 21st Jun 2005 08:52 PM
Code for deleting entire row gregork Microsoft Excel Programming 2 4th Jul 2004 12:13 PM
Deleting entire rows Ed C Microsoft Excel Programming 2 18th Jun 2004 02:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:14 PM.