PC Review


Reply
Thread Tools Rate Thread

Delete Rows that do not contain

 
 
SITCFanTN
Guest
Posts: n/a
 
      19th Nov 2009
I want to create a macro that will run through 10,000 plus rows and quickly
delete all rows if Col A does not contain the text of T75TA. Any help you
can provide is greatly appreciated, thank you.
 
Reply With Quote
 
 
 
 
Paul C
Guest
Posts: n/a
 
      19th Nov 2009
This should do the trick

Sub DeleteRows()

Dim findstring As String

lastrow = Range("A15000").End(xlUp).Row
findstring = "T75TA"
For A = lastrow To 1 Step -1
If InStr(CStr(Cells(A, 1)), findstring) < 1 Then Cells(A,
1).EntireRow.Delete
Next A

End Sub
--
If this helps, please remember to click yes.


"SITCFanTN" wrote:

> I want to create a macro that will run through 10,000 plus rows and quickly
> delete all rows if Col A does not contain the text of T75TA. Any help you
> can provide is greatly appreciated, thank you.

 
Reply With Quote
 
Mike
Guest
Posts: n/a
 
      19th Nov 2009
this will work

Option Explicit
Sub Remove_Unwanted_Rows()
'this deletes all rows with cells exactly matching cases
Dim rng As Range
Dim cell, RowArray As Range
Set rng = ActiveSheet.Range(Cells(1, "A"), Cells(Rows.Count, "A").End(xlUp))
For Each cell In rng
Select Case cell
Case Is = "T75TA"
If RowArray Is Nothing Then
Set RowArray = cell.EntireRow
Else
Set RowArray = Union(RowArray, cell.EntireRow)
End If
End Select
Next cell
On Error Resume Next
RowArray.Delete
Err.Clear
End Sub

"SITCFanTN" wrote:

> I want to create a macro that will run through 10,000 plus rows and quickly
> delete all rows if Col A does not contain the text of T75TA. Any help you

this > can provide is greatly appreciated, thank you.
 
Reply With Quote
 
Jarek Kujawa
Guest
Posts: n/a
 
      19th Nov 2009
Sub cus()

For i = 10000 To 1 Step -1
If Len(Cells(i, 1)) And InStr(1, "T75TA", Cells(i, 1)) Then Cells
(i, 1).Rows.EntireRow.Delete
Next i

End Sub


On 19 Lis, 14:59, SITCFanTN <SITCFa...@discussions.microsoft.com>
wrote:
> I want to create a macro that will run through 10,000 plus rows and quickly
> delete all rows if Col A does not contain the text of T75TA. * *Any help you
> can provide is greatly appreciated, thank you.


 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      19th Nov 2009
Give this macro a try, just set the 3 constant (Const) statements at the
beginning to match your actual set up...

Sub RemoveNotCurrentRecords()
Dim X As Long
Dim LastRow As Long
Dim OriginalCalculationMode As Long
Dim RowsToDelete As Range

Const DataStartRow As Long = 2
Const TestColumn As String = "A"
Const SheetName As String = "Sheet1"

On Error GoTo Whoops
OriginalCalculationMode = Application.Calculation
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False

With Worksheets(SheetName)
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
For X = LastRow To DataStartRow Step -1
' <<Set your test condition here>>
If UCase(.Cells(X, TestColumn).Value) = "T75TA" Then
If RowsToDelete Is Nothing Then
Set RowsToDelete = .Cells(X, TestColumn)
Else
Set RowsToDelete = Union(RowsToDelete, .Cells(X, TestColumn))
End If
If RowsToDelete.Areas.Count > 100 Then
RowsToDelete.EntireRow.Delete xlShiftUp
Set RowsToDelete = Nothing
End If
End If
Next
End With
If Not RowsToDelete Is Nothing Then
RowsToDelete.EntireRow.Delete xlShiftUp
End If

Whoops:
Application.Calculation = OriginalCalculationMode
Application.ScreenUpdating = True
End Sub


--
Rick (MVP - Excel)


"SITCFanTN" <(E-Mail Removed)> wrote in message
news:A1A246D0-392C-4CD7-9CD7-(E-Mail Removed)...
>I want to create a macro that will run through 10,000 plus rows and quickly
> delete all rows if Col A does not contain the text of T75TA. Any help
> you
> can provide is greatly appreciated, thank you.


 
Reply With Quote
 
SITCFanTN
Guest
Posts: n/a
 
      19th Nov 2009
I only want to keep the rows with T75TA, all the others I need to delete. I
could not get this to work...am I doing something wrong? Thank you.

"Jarek Kujawa" wrote:

> Sub cus()
>
> For i = 10000 To 1 Step -1
> If Len(Cells(i, 1)) And InStr(1, "T75TA", Cells(i, 1)) Then Cells
> (i, 1).Rows.EntireRow.Delete
> Next i
>
> End Sub
>
>
> On 19 Lis, 14:59, SITCFanTN <SITCFa...@discussions.microsoft.com>
> wrote:
> > I want to create a macro that will run through 10,000 plus rows and quickly
> > delete all rows if Col A does not contain the text of T75TA. Any help you
> > can provide is greatly appreciated, thank you.

>
> .
>

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      19th Nov 2009
I think I have my test backwards. Change this line...

If UCase(.Cells(X, TestColumn).Value) = "T75TA" Then

to this..

If UCase(.Cells(X, TestColumn).Value) <> "T75TA" Then

--
Rick (MVP - Excel)


"Rick Rothstein" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Give this macro a try, just set the 3 constant (Const) statements at the
> beginning to match your actual set up...
>
> Sub RemoveNotCurrentRecords()
> Dim X As Long
> Dim LastRow As Long
> Dim OriginalCalculationMode As Long
> Dim RowsToDelete As Range
>
> Const DataStartRow As Long = 2
> Const TestColumn As String = "A"
> Const SheetName As String = "Sheet1"
>
> On Error GoTo Whoops
> OriginalCalculationMode = Application.Calculation
> Application.Calculation = xlCalculationManual
> Application.ScreenUpdating = False
>
> With Worksheets(SheetName)
> LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
> For X = LastRow To DataStartRow Step -1
> ' <<Set your test condition here>>
> If UCase(.Cells(X, TestColumn).Value) = "T75TA" Then
> If RowsToDelete Is Nothing Then
> Set RowsToDelete = .Cells(X, TestColumn)
> Else
> Set RowsToDelete = Union(RowsToDelete, .Cells(X, TestColumn))
> End If
> If RowsToDelete.Areas.Count > 100 Then
> RowsToDelete.EntireRow.Delete xlShiftUp
> Set RowsToDelete = Nothing
> End If
> End If
> Next
> End With
> If Not RowsToDelete Is Nothing Then
> RowsToDelete.EntireRow.Delete xlShiftUp
> End If
>
> Whoops:
> Application.Calculation = OriginalCalculationMode
> Application.ScreenUpdating = True
> End Sub
>
>
> --
> Rick (MVP - Excel)
>
>
> "SITCFanTN" <(E-Mail Removed)> wrote in message
> news:A1A246D0-392C-4CD7-9CD7-(E-Mail Removed)...
>>I want to create a macro that will run through 10,000 plus rows and
>>quickly
>> delete all rows if Col A does not contain the text of T75TA. Any help
>> you
>> can provide is greatly appreciated, thank you.

>


 
Reply With Quote
 
Jarek Kujawa
Guest
Posts: n/a
 
      20th Nov 2009
mu fault, misread your post

this should be better

Sub cus()
For i = 20 To 1 Step -1
Cells(i, 1).Activate
If Len(Cells(i, 1)) And InStr(1, "T75TA", Cells(i, 1)) = 0 Then
Cells(i, 1).Rows.EntireRow.Delete
Next i
End Sub



On 19 Lis, 22:39, SITCFanTN <SITCFa...@discussions.microsoft.com>
wrote:
> I only want to keep the rows with T75TA, all the others I need to delete.Â*I
> could not get this to work...am I doing something wrong? Â*Thank you.
>
>
>
> "Jarek Kujawa" wrote:
> > Sub cus()

>
> > For i = 10000 To 1 Step -1
> > Â* Â* If Len(Cells(i, 1)) And InStr(1, "T75TA", Cells(i, 1)) Then Cells
> > (i, 1).Rows.EntireRow.Delete
> > Next i

>
> > End Sub

>
> > On 19 Lis, 14:59, SITCFanTN <SITCFa...@discussions.microsoft.com>
> > wrote:
> > > I want to create a macro that will run through 10,000 plus rows and quickly
> > > delete all rows if Col A does not contain the text of T75TA. Â* Â*Any help you
> > > can provide is greatly appreciated, thank you.

>
> > .- Ukryj cytowany tekst -

>
> - Pokaż cytowany tekst -


 
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
Autofil on variable rows, delete extract and show remaining rows 1plane Microsoft Excel Programming 3 17th Nov 2009 10:49 AM
Hpw do I delete multiple empty rows found between filled rows? Bill Microsoft Excel Worksheet Functions 1 15th Nov 2009 12:52 AM
Copy pasting Rows, but need to Delete any Shapes/Pictures that are within copied rows Corey Microsoft Excel Programming 2 1st Aug 2007 02:02 AM
Cut filtered rows, paste into next empty row of new sheet, and delete cut rows Scott Microsoft Excel Worksheet Functions 0 13th Dec 2006 01:25 AM
Delete rows with numeric values, leave rows with text =?Utf-8?B?R1NwbGluZQ==?= Microsoft Excel Programming 5 11th Oct 2005 12:44 AM


Features
 

Advertising
 

Newsgroups
 


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