Eliminate undesired rows

rdev

Active Member
Joined
Dec 3, 2007
Messages
273
-------- -----
Inter Op eration Ctl - 1102
<-Sour ce--> Transaction Desc ription Trxn
Co Acc ount Extension Co de Typ Doc.Ref. Date Session Perd.
-- --- ----- ---------------- -------------- --- -------- -------- ------- -----
ST TRANSFER TO 1102PAY CJT 20145417 23/06/08 183137 806
SH.ST.9999
ST TRANSFER TO 1102PAY CJT 20145419 30/06/08 183140 806
SH.ST.9999
ST TRANSFER TO 1102PAY CJT 20145421 30/06/08 183140 806


I have the following codes to delete those rows that do not have ST in the first column . It does work for the blank rows but bot for rows other than the ST e.g the inter op remains,can someone help


Sub Tiedup1102()
Dim finalrow, t As Long, y As Constants
Sheets("1102").Select
Cells(13, 1).Select
y = Trim(Cells(13, 1).Value) ' extract a string from a cell

'LastRow2 = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
'MsgBox LastRow2
For t = 13 To 2500
Cells(t, 1).Select
If Trim(Cells(t, 1).Value) <> "ST" Then ActiveCell.EntireRow.Delete
Next t
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Could it be because your code only looks at rows 13 to 2500?

Also, there's no need to select cells to work with them. The following would be more efficient:

Code:
Sub Tiedup1102()
Dim LastRow2, t As Long
With Sheets("1102")

LastRow2 = .Range("A" & Rows.Count).End(xlUp).Row

For t = LastRow2 to 1 Step-1 'assumes your data to be tested starts from row 1

If Trim(.Cells(t, 1).Value) <> "ST" Then .Cells(t,1).EntireRow.Delete
Next t
End With
End Sub
 
Upvote 0
Hi RDev
Perhaps something like this:-
Code:
Dim T As Integer, Last As Integer
Last = Range("A" & Columns.Count).End(xlUp).Row
  
  For T = Last To 13 Step -1
      If InStr(Cells(T, 1).Value, "ST") = 0 Or _
         Cells(T, 1).Value = "" Then
            Rows(T).EntireRow.Delete
      End If
Next T
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top