#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default Macro to delete row

Hi, i need a macro to delete rows that don't have in "H" column the name "John"
If in "H" column the code finds anything else, then to delete row.
Can this be done?
Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 561
Default Macro to delete row

Hi,
One approach might be:
=================
Sub John()
LR = [H65536].End(xlUp).Row
For R = LR To 1 Step -1
If Cells(R, 8) < "John" Then Cells(R, 8).EntireRow.Delete
Next
End Sub
========
Micky


"puiuluipui" wrote:

Hi, i need a macro to delete rows that don't have in "H" column the name "John"
If in "H" column the code finds anything else, then to delete row.
Can this be done?
Thanks!

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Macro to delete row

Hi

'Delete if not cell match
Sub DeleteRows()
Dim lngRow As Long
For lngRow = Cells(Rows.Count, "H").End(xlUp).Row To 1 Step -1
If StrComp(Range("H" & lngRow), "John", vbTextCompare) < 0 Then
Rows(lngRow).Delete
End If
Next
End Sub


'delete rows if the word 'john' is not found within the cell
Sub DeleteRows()
Dim lngRow As Long
For lngRow = Cells(Rows.Count, "H").End(xlUp).Row To 1 Step -1
If InStr(1, Range("H" & lngRow), "john", vbTextCompare) = 0 Then
Rows(lngRow).Delete
End If
Next
End Sub



--
Jacob


"puiuluipui" wrote:

Hi, i need a macro to delete rows that don't have in "H" column the name "John"
If in "H" column the code finds anything else, then to delete row.
Can this be done?
Thanks!

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,124
Default Macro to delete row


sub delifnotjohn()'if John is not within other text
for i=cells(rows.count,"H").end(xlup).row to 1 step -1
if ucase(cells(i,"h"))<"JOHN" then rows(i).delete
next i
end sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"puiuluipui" wrote in message
...
Hi, i need a macro to delete rows that don't have in "H" column the name
"John"
If in "H" column the code finds anything else, then to delete row.
Can this be done?
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
Macro warning - how to delete macro GavinS Excel Worksheet Functions 3 April 1st 09 01:45 PM
Cannot Delete Macro dk New Users to Excel 3 November 14th 06 07:21 PM
delete a macro that isn't in macro list Jane Makinson Excel Discussion (Misc queries) 3 March 13th 06 01:10 PM
How can I delete a macro when the Delete button is not active? FCR Excel Worksheet Functions 0 March 9th 06 09:43 AM
How do i delete a macro in Excel 2003 when delete isn't highlight Abel Excel Discussion (Misc queries) 2 September 13th 05 04:09 AM


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

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"