PC Review


Reply
Thread Tools Rate Thread

delete every row where value equals user input

 
 
Mitchell_Collen via OfficeKB.com
Guest
Posts: n/a
 
      18th Oct 2007
Hi all.
The code pasted below works only it will not search and delete every row
equal to user value. I have had to press ctrl+b, then enter value such as
'cardiac' over and over. It will delete the row where there is a cell
containing the value cardiac however, it will not delete all rows where the
row contains cardiac. There are 4000+ rows with cardiac and other words that
need to be deleted off the spreadsheet. I know it must be loop but I don't
have any syntax reference or books. Please help me. Thanks in advance. Misty

Here is the code:

Sub Macro3()
' Keyboard Shortcut: Ctrl+b
Dim userResponse
With Worksheets(1).Range("A1:H100")
userResponse = Application.InputBox("Enter a value where the rows are to be
deleted")
Set c = .Find(userResponse, LookIn:=xlValues)
If Not c Is Nothing Then
c.EntireRow.Delete
End If
End With
End Sub

--
Message posted via http://www.officekb.com

 
Reply With Quote
 
 
 
 
Thomas Ramel
Guest
Posts: n/a
 
      18th Oct 2007
Grüezi Misty

Mitchell_Collen via OfficeKB.com schrieb am 18.10.2007

> The code pasted below works only it will not search and delete every row
> equal to user value. I have had to press ctrl+b, then enter value such as
> 'cardiac' over and over. It will delete the row where there is a cell
> containing the value cardiac however, it will not delete all rows where the
> row contains cardiac. There are 4000+ rows with cardiac and other words that
> need to be deleted off the spreadsheet. I know it must be loop but I don't
> have any syntax reference or books. Please help me. Thanks in advance. Misty


Maybe you will find the following lines useful (even if the variables are
in German:

Public Sub DelRows(rngSpalte As Range, varValue As Variant)
'© Thomas Ramel / 24.01.2005
'Funktion zum Löschen ganzer Zeilen eines Tabellenblattes unter
'Berücksichtigung von Kriterien
'Bedingung: nicht mehr als 8125 unzusammenhängende Bereiche als Ergebnis
'Die Funktion kann nur von VBA aufgerufen werden *nicht* in einer Zelle
'Folgender Aufruf löscht alle Zeilen wenn in Spalte A '10' enthalten ist:
'DelRows Range("A:A"), 10

Application.ScreenUpdating = False
Application.Calculation = xlManual
If Application.WorksheetFunction.CountIf(rngSpalte, varValue) > 0 Then
If varValue = "" Then
rngSpalte.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
Else
With rngSpalte
.Replace "", "##@@##", xlWhole
.Replace varValue, "", xlWhole
.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
.Replace "##@@##", "", xlWhole
End With
End If
End If
Application.Calculation = xlAutomatic
Application.ScreenUpdating = True
End Sub

Run the following line for your purposes:


Sub DelRowsTest()
DelRows Range("A1:H100"), _
Application.InputBox("Enter a value where " & _
"the rows are to be deleted ")
End Sub



Mit freundlichen Grüssen
Thomas Ramel

--
- MVP für Microsoft-Excel -
[Win XP Pro SP-2 / xl2003 SP-2]
Microsoft Excel - Die ExpertenTipps
 
Reply With Quote
 
Otto Moehrbach
Guest
Posts: n/a
 
      18th Oct 2007
Misty
This should do what you want. HTH Otto
Sub Macro3()
Dim userResponse
Dim c As Range
Dim b As Long
With Worksheets(1).Range("A1:H100")
userResponse = InputBox("Enter a value where the rows are to be
deleted.")
For b = 1 To 100 'Number >= count of rows in the above range
Set c = Nothing
Set c = .Find(What:=userResponse, LookIn:=xlValues)
If Not c Is Nothing Then
c.EntireRow.Delete
Else
Exit For
End If
Next b
End With
End Sub
"Mitchell_Collen via OfficeKB.com" <u33726@uwe> wrote in message
news:79e27dfb52b63@uwe...
> Hi all.
> The code pasted below works only it will not search and delete every row
> equal to user value. I have had to press ctrl+b, then enter value such as
> 'cardiac' over and over. It will delete the row where there is a cell
> containing the value cardiac however, it will not delete all rows where
> the
> row contains cardiac. There are 4000+ rows with cardiac and other words
> that
> need to be deleted off the spreadsheet. I know it must be loop but I don't
> have any syntax reference or books. Please help me. Thanks in advance.
> Misty
>
> Here is the code:
>
> Sub Macro3()
> ' Keyboard Shortcut: Ctrl+b
> Dim userResponse
> With Worksheets(1).Range("A1:H100")
> userResponse = Application.InputBox("Enter a value where the rows are to
> be
> deleted")
> Set c = .Find(userResponse, LookIn:=xlValues)
> If Not c Is Nothing Then
> c.EntireRow.Delete
> End If
> End With
> End Sub
>
> --
> Message posted via http://www.officekb.com
>



 
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
Delete Certain Rows Based on User Input kmzito@gmail.com Microsoft Excel Programming 1 12th May 2009 01:03 AM
input of selected cells equals content of another cell al Microsoft Excel Programming 2 20th Jan 2009 12:34 PM
Delete Row if Value in Column L equals zero Aaron Microsoft Excel Programming 3 28th Nov 2007 04:23 PM
Delete Columns if value equals zero Freddy Microsoft Excel Programming 2 28th Nov 2007 11:41 AM
VBA Code to auto perform append/delete queries (no user input) =?Utf-8?B?Q01B?= Microsoft Access VBA Modules 3 28th Mar 2007 06:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:30 PM.