Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default deleting multiple rows with multiple criteria

Hello: looking for code to a macro that will delete rows based on multiple
critera. For example, worksheet has 10,000 rows of data; however, need to
delete any row that begin with (no quotes):

"ACTH"
"#55"
"-----"

Some rows may have ACTH-4577, but still need to be delted b/c the have the
"ACTH" at the beginning.

Thanks!




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 212
Default deleting multiple rows with multiple criteria

Hi Pablo,

1. Copy the below code in to a module:

Sub KillRows()
Dim c1, c2
Dim strRange As Range, killRange As Range
Set strRange = Selection
With Sheet1.UsedRange
Set killRange = Sheet1.Cells(.Cells.Rows.Count + 1, 1)
For Each c1 In strRange.Cells
For Each c2 In .Cells
If (Not IsEmpty(c1)) And InStr(1, Trim(c2.Value),
Trim(c1.Value)) 0 Then
If Application.Intersect(c2.EntireRow, killRange) Is Nothing
Then
Set killRange = Union(killRange, c2)
End If
End If
Next c2
Next c1
End With
If killRange.Cells.Count = 1 Then
MsgBox "None of the enterted text strings were found!", vbCritical
Else
killRange.EntireRow.Delete
End If
Set killRange = Nothing
Set strRange = Nothing
End Sub

2. I assumed above that the name of sheet containing your rows is "Sheet1",
Change it to name of your sheet.

3. On another sheet (if necessary insert a blank sheet), enter the text
string to be searched
in to seperate cells.
e.g.: in A1 enter ACTH, in A2 enter #55, in A3 enter ---- .
Please note you must do it either in a seperate sheet OR in the same sheet
BELOW the last used row.

4. Select all the cells where you entered the search text as in step 3
above.

5. Run the macro KillRows

Sharad

"Pablo" wrote in message
...
Hello: looking for code to a macro that will delete rows based on multiple
critera. For example, worksheet has 10,000 rows of data; however, need to
delete any row that begin with (no quotes):

"ACTH"
"#55"
"-----"

Some rows may have ACTH-4577, but still need to be delted b/c the have the
"ACTH" at the beginning.

Thanks!






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default deleting multiple rows with multiple criteria

Thanks for the help. However, I've tried to run this a couple times and
keep getting the message, "Object Required". Then the debugger
highlights this:

Set killRange = CCDA.Cells(.Cells.Rows.Count + 1, 1)


Also, is there a way to identify what row the macro will start? For
example, if I have the header "Apples from Washington" starting in row
1 and repeated every 75th row, can I somehow tell the macro to ignore
row 1? (ie-highlight the range I want the macro to run against?)




Sharad Naik wrote:
Hi Pablo,

1. Copy the below code in to a module:

Sub KillRows()
Dim c1, c2
Dim strRange As Range, killRange As Range
Set strRange = Selection
With Sheet1.UsedRange
Set killRange = Sheet1.Cells(.Cells.Rows.Count + 1, 1)
For Each c1 In strRange.Cells
For Each c2 In .Cells
If (Not IsEmpty(c1)) And InStr(1, Trim(c2.Value),
Trim(c1.Value)) 0 Then
If Application.Intersect(c2.EntireRow, killRange) Is

Nothing
Then
Set killRange = Union(killRange, c2)
End If
End If
Next c2
Next c1
End With
If killRange.Cells.Count = 1 Then
MsgBox "None of the enterted text strings were found!",

vbCritical
Else
killRange.EntireRow.Delete
End If
Set killRange = Nothing
Set strRange = Nothing
End Sub

2. I assumed above that the name of sheet containing your rows is

"Sheet1",
Change it to name of your sheet.

3. On another sheet (if necessary insert a blank sheet), enter the

text
string to be searched
in to seperate cells.
e.g.: in A1 enter ACTH, in A2 enter #55, in A3 enter ---- .
Please note you must do it either in a seperate sheet OR in the same

sheet
BELOW the last used row.

4. Select all the cells where you entered the search text as in step

3
above.

5. Run the macro KillRows

Sharad

"Pablo" wrote in message
...
Hello: looking for code to a macro that will delete rows based on

multiple
critera. For example, worksheet has 10,000 rows of data; however,

need to
delete any row that begin with (no quotes):

"ACTH"
"#55"
"-----"

Some rows may have ACTH-4577, but still need to be delted b/c the

have the
"ACTH" at the beginning.

Thanks!





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default deleting multiple rows with multiple criteria

Thanks for the help. However, I've tried to run this a couple times and
keep getting the message, "Object Required". Then the debugger
highlights this:


Set killRange = CCDA.Cells(.Cells.Rows.Count + 1, 1)


Also, is there a way to identify what row the macro will start? For
example, if I have the header "Apples from Washington" starting in row
1 and repeated every 75th row, can I somehow tell the macro to ignore
row 1? (ie-highlight the range I want the macro to run against?)






"Sharad Naik" wrote in message
...
Hi Pablo,

1. Copy the below code in to a module:

Sub KillRows()
Dim c1, c2
Dim strRange As Range, killRange As Range
Set strRange = Selection
With Sheet1.UsedRange
Set killRange = Sheet1.Cells(.Cells.Rows.Count + 1, 1)
For Each c1 In strRange.Cells
For Each c2 In .Cells
If (Not IsEmpty(c1)) And InStr(1, Trim(c2.Value),
Trim(c1.Value)) 0 Then
If Application.Intersect(c2.EntireRow, killRange) Is
Nothing Then
Set killRange = Union(killRange, c2)
End If
End If
Next c2
Next c1
End With
If killRange.Cells.Count = 1 Then
MsgBox "None of the enterted text strings were found!", vbCritical
Else
killRange.EntireRow.Delete
End If
Set killRange = Nothing
Set strRange = Nothing
End Sub

2. I assumed above that the name of sheet containing your rows is
"Sheet1",
Change it to name of your sheet.

3. On another sheet (if necessary insert a blank sheet), enter the text
string to be searched
in to seperate cells.
e.g.: in A1 enter ACTH, in A2 enter #55, in A3 enter ---- .
Please note you must do it either in a seperate sheet OR in the same sheet
BELOW the last used row.

4. Select all the cells where you entered the search text as in step 3
above.

5. Run the macro KillRows

Sharad

"Pablo" wrote in message
...
Hello: looking for code to a macro that will delete rows based on
multiple
critera. For example, worksheet has 10,000 rows of data; however, need to
delete any row that begin with (no quotes):

"ACTH"
"#55"
"-----"

Some rows may have ACTH-4577, but still need to be delted b/c the have
the
"ACTH" at the beginning.

Thanks!








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting Multiple Blank Rows Diabolo_Devil[_2_] Excel Discussion (Misc queries) 6 March 12th 10 03:20 PM
How to retrieve multiple values in multiple rows with one criteria bac Excel Discussion (Misc queries) 2 June 15th 07 08:57 PM
Deleting a rows from multiple worksheets School Teacher Excel Worksheet Functions 0 July 6th 05 06:52 PM
deleting multiple rows Pablo Excel Discussion (Misc queries) 4 January 27th 05 07:18 PM
Deleting rows based on multiple criteria Sandip Shah Excel Programming 3 July 12th 04 01:57 PM


All times are GMT +1. The time now is 10:39 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"