PC Review


Reply
Thread Tools Rate Thread

Delete Certain Rows Based on User Input

 
 
kmzito@gmail.com
Guest
Posts: n/a
 
      12th May 2009
Hi everyone,

The below macro is the beginning half of what I'm working with.

What I need it to do is Prompt the user for a vendor name, find it on
the 'List" sheet, then delete all rows that contain the same values
(all rows that it needs to delete would be the same with the exception
being the the A column). I would just have it sort and automatically
delete like 5 or 10 but the issue is sometimes its 4, sometimes 1
sometimes 12, etc.


Dim sUsername As String
Dim sPrompt As String

sPrompt = "Please enter vendor name"
sUsername = InputBox(sPrompt, sTitle, sDefault)

Sheets("list").Select
Range("d4").Select
Cells.Find(What:=sUsername, After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Select

Answer = MsgBox("Is this the contract/vendor you would like to
delete?", vbYesNo + vbInformation, "Please Confirm")
If Answer = vbYes Then
Selection.EntireRow.Delete

Exit Sub
 
Reply With Quote
 
 
 
 
ryguy7272
Guest
Posts: n/a
 
      12th May 2009
Sub SortDelete()
Dim sUsername As String
Dim sPrompt As String
sPrompt = "Please enter vendor name"
sUsername = InputBox(sPrompt, sTitle, sDefault)
Sheets("list").Select
Range("d4").Select
Cells.Find(What:=sUsername, After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Select
Answer = MsgBox("Is this the contract/vendor you would like to delete?",
vbYesNo + vbInformation, "Please Confirm")
If Answer = vbYes Then

Dim myrange, MyRange1 As Range
LastRow = Cells(Rows.Count, "D").End(xlUp).Row
Set myrange = Sheets("list").Range("D4" & LastRow)
For Each C In myrange
If (C.Value) = sUsername Then
If MyRange1 Is Nothing Then
Set MyRange1 = C.EntireRow
Else
Set MyRange1 = Union(MyRange1, C.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If
End If
Exit Sub
End Sub

HTH,'
Ryan---
--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"(E-Mail Removed)" wrote:

> Hi everyone,
>
> The below macro is the beginning half of what I'm working with.
>
> What I need it to do is Prompt the user for a vendor name, find it on
> the 'List" sheet, then delete all rows that contain the same values
> (all rows that it needs to delete would be the same with the exception
> being the the A column). I would just have it sort and automatically
> delete like 5 or 10 but the issue is sometimes its 4, sometimes 1
> sometimes 12, etc.
>
>
> Dim sUsername As String
> Dim sPrompt As String
>
> sPrompt = "Please enter vendor name"
> sUsername = InputBox(sPrompt, sTitle, sDefault)
>
> Sheets("list").Select
> Range("d4").Select
> Cells.Find(What:=sUsername, After:=ActiveCell, LookIn:=xlFormulas,
> LookAt _
> :=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
> MatchCase:= _
> False, SearchFormat:=False).Select
>
> Answer = MsgBox("Is this the contract/vendor you would like to
> delete?", vbYesNo + vbInformation, "Please Confirm")
> If Answer = vbYes Then
> Selection.EntireRow.Delete
>
> Exit Sub
>

 
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
Macro to delete rows based based between two specific dates Trey24 Microsoft Excel Misc 0 25th Aug 2009 05:05 PM
Delete rows based on date input bingshuo.li@gmail.com Microsoft Excel Programming 3 17th Nov 2008 11:01 PM
show a number of rows based upon user input P_R Microsoft Excel Misc 1 22nd Apr 2008 08:03 AM
Hiding rows based on user input =?Utf-8?B?UmFuZHk=?= Microsoft Excel Programming 1 7th May 2007 11:50 PM
CODE to select range based on User Input or Value of Input Field Sandi Gauthier Microsoft Excel Programming 4 8th Dec 2003 03:22 PM


Features
 

Advertising
 

Newsgroups
 


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