Deleting row dependent upon drop-down list value

B

Ben Allen

I have a drop down list in which the user selects a tour refrence number.
Text boxes are then filled in automatically. When the user clicks the remove
button i need it to delete the row which conatins the selected tour
refrence.
Thanks guys,
--
Cheers,
Ben

Remove your.tonsils to reply
"You only live once but if you do it right once is enough!"
 
T

Tom Ogilvy

Dim rng as Range
set rng = Range(Cells(2,1),Cells(2,1).End(xldown)
res = Application.Match(textbox1.Text,rng,0)
if not iserror(res) then
rng(res).EntireRow.Delete
End if
 
B

Ben Allen

Cheers Tom, I have no errors with this code but it just doesnt do anything,
any ideas?
Thanks
--
Cheers,
Ben

Remove your.tonsils to reply
"You only live once but if you do it right once is enough!"
 
B

Ben Allen

My code is as follows:

'Remove
Private Sub Remove_Click()
'Selecting "Select"
If tourref.Value = "Select" Then
MsgBox "You must select a valid tour", vbExclamation, "Error"
End If
'Message
If MsgBox("You are are about to remove this tour from the spreadsheet. Do
you wish to continue?", vbYesNo, "Remove?") = vbYes _
Then
'Delete Tour
Dim rng As Range
Set rng = Range(Cells(2, 1), Cells(2, 1).End(xlDown))
res = Application.Match(tourref.Value, rng, 0)
If Not IsError(res) Then
rng(res).EntireRow.Delete
End If

End If
End Sub
--
Cheers,
Ben

Remove your.tonsils to reply
"You only live once but if you do it right once is enough!"
 
B

Ben Allen

Ok guys, got it sorted:

'Remove
Private Sub Remove_Click()
'Selecting "Select"
If tourref.Value = "Select" Then
MsgBox "You must select a valid tour", vbExclamation, "Error"
End If
'Message
If MsgBox("You are are about to remove this tour from the spreadsheet. Do
you wish to continue?", vbYesNo, "Remove?") = vbYes _
Then
'Delete Tour
Res = Application.Match(tourref.Text, Range("B4:B4000"), 0) + 3
If IsError(Res) Then
MsgBox "Not Found"
Else
Rows(Res).Delete
End If
End If
End Sub
--
Cheers,
Ben

Remove your.tonsils to reply
"You only live once but if you do it right once is enough!"
 

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