Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi,
I'm trying to write a macro the deletes all rows that don't contain the numbers 10 in row A. The numbers will range from 102000 to 1099999. I want to delete all rows that don't have any of these numbers in the first column. Thanks for any help |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi,
I think your saying that if the number in column A doesn't begin with 10 then delete the entire row. If that's correct then right click your sheet tab, view code and paste this in and run it. If that's wrong then post back. Sub Standard() mycolumn = "A" 'Change to suit Dim MyRange, MyRange1 As Range LastRow = Cells(Rows.Count, mycolumn).End(xlUp).Row Set MyRange = Range(mycolumn & "1:" & mycolumn & LastRow) For Each c In MyRange If InStr(CStr((c.Value)), "10") < 1 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 Sub Mike "nrfinsa" wrote: Hi, I'm trying to write a macro the deletes all rows that don't contain the numbers 10 in row A. The numbers will range from 102000 to 1099999. I want to delete all rows that don't have any of these numbers in the first column. Thanks for any help |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi,
Reading your post again you do say 'Don't contain' so change If InStr(CStr((c.Value)), "10") < 1 Then to If InStr(CStr(c.Value), "10") = 0 Then and it will dlete every row that doesn't 'contain' a 10. Note i've knocked out a set of parenthesis that weren't necessary. Mike "Mike H" wrote: Hi, I think your saying that if the number in column A doesn't begin with 10 then delete the entire row. If that's correct then right click your sheet tab, view code and paste this in and run it. If that's wrong then post back. Sub Standard() mycolumn = "A" 'Change to suit Dim MyRange, MyRange1 As Range LastRow = Cells(Rows.Count, mycolumn).End(xlUp).Row Set MyRange = Range(mycolumn & "1:" & mycolumn & LastRow) For Each c In MyRange If InStr(CStr((c.Value)), "10") < 1 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 Sub Mike "nrfinsa" wrote: Hi, I'm trying to write a macro the deletes all rows that don't contain the numbers 10 in row A. The numbers will range from 102000 to 1099999. I want to delete all rows that don't have any of these numbers in the first column. Thanks for any help |
#4
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]() Thanks Mike, That worked perfectly :-) Neville |
#5
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Mike
Is it possible to add other choices to keep rows, This works fine for my number range, but I would like to keep 17 and 2 types of text SHS and TFG and then delete all other rows Regards Johnny "Mike H" wrote: Hi, I think your saying that if the number in column A doesn't begin with 10 then delete the entire row. If that's correct then right click your sheet tab, view code and paste this in and run it. If that's wrong then post back. Sub Standard() mycolumn = "A" 'Change to suit Dim MyRange, MyRange1 As Range LastRow = Cells(Rows.Count, mycolumn).End(xlUp).Row Set MyRange = Range(mycolumn & "1:" & mycolumn & LastRow) For Each c In MyRange If InStr(CStr((c.Value)), "10") < 1 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 Sub Mike "nrfinsa" wrote: Hi, I'm trying to write a macro the deletes all rows that don't contain the numbers 10 in row A. The numbers will range from 102000 to 1099999. I want to delete all rows that don't have any of these numbers in the first column. Thanks for any help |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
I want to delete all even rows? | Excel Discussion (Misc queries) | |||
How to Delete empty rows in excel in b/w rows with values | Excel Worksheet Functions | |||
Cut filtered rows, paste into next empty row of new sheet, and delete cut rows | Excel Worksheet Functions | |||
How to delete rows when List toolbar's "delete" isnt highlighted? | Excel Worksheet Functions | |||
delete empty rows between rows with text | Excel Discussion (Misc queries) |