LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default delete entire row based on value

Gauthier,

Try this sub, which will place a formula in column AA on which to base the
deletion. This assumes that you have headers in row 1.

Sub DeleteRows()
Dim myRow As Long
Dim myR As Range

myRow = Range("A1").SpecialCells(xlCellTypeLastCell).Row
Range("AA1").Value = "Save Key"
Range("AA2:AA" & myRow).Formula = _
"=IF(OR(A2=""SEQ: T"",A2=""TOTAL"",B2=""SVC""," & _
"LEFT(C2,14)=""EXCHANGE RATE:""),""Keep"",""Delete"")"
Range("AA2:AA" & myRow).Value = Range("AA2:AA" & myRow).Value
Columns("A:AA").Sort Key1:=Range("AA2"), _
Order1:=xlDescending, Header:=xlYes
Set myR = Range("AA2:AA" & myRow).Find(What:="Delete", _
After:=Range("AA2"), LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
Range(myR, Range("AA65536").End(xlUp)).EntireRow.Delete
Range("AA1").EntireColumn.Delete
End Sub

HTH,
Bernie
MS Excel MVP

"Gauthier" wrote in message
...
Hi there...below is the code currently contained in my workbook...i should
pre-empt with the fact that my VBA knowledge is basic at best - and i'm
using excel 2000...

My "history data" was actually a .txt document, that i converted to excel
using the delimited function...there's a lot of giberish and blank rows

that
i want to DELETE...

i've determined the FIELD contents, for the ROWS that i wish to KEEP, and
would appreciate any assistance in establishing the code...

the FIELD contents for the ROWS i wish to KEEP are as follows:

- Column A contains "SEQ: T"
- Column A contains "TOTAL"
- Column B contains "SVC"
- Column C contains "EXCHANGE RATE:" note-the text EXCHANGE RATE: is
followed by a series of exchange rates that vary - but as long as it

STARTS
with "EXCHANGE RATE:" keep the row

appreciate your assistance!
Sandi

--------------------------------------------------------------------------

--
-----

Sub FormatHistory()

' TURNS SCREEN UPDATING OFF
Application.ScreenUpdating = False

' STATUS BAR MESSAGE IS ACTIVATED
Application.StatusBar = "Formatting Report, Please Wait..."

' INSERTS FORMULA INTO COLUMN I TO SUBTRACT COLUMNS E,F,G, FROM H
("TOTAL")
' TO ROWS BEGINNING WITH "TOTAL"

' EXTENDS FORMULAS IN COLUMN I TO END OF ROW
Set SH = ThisWorkbook.Worksheets("simhistory")

' FINDS THE LAST ROW OF ACTUAL DATA
LR = SH.Range("A65536").End(xlUp).Row

' THIS CLEARS OUT ALL OF THE FORMULAES FROM COLUMN I
SH.Range("I2:I65536").ClearContents

' THIS ADDS THE FORMULAS TO COLUMN I
If LR 1 Then
'IF THERE IS AT LEAST 1 ROW OF DATA, THEN IT WILL PUT IN THESE
'FORMULAS IN ROW 2 (FORMULA TO CALCULATE REV. FOR $50+)
SH.Range("I2").Formula =
"=IF(A2=""TOTAL"",IF(H20,H2-E2-F2-G2,""""))"
If LR 2 Then
'IF THERE IS MORE THAN 1 ROW OF DATA, THEN IT WILL FILL DOWN THE
'FORMULA IN I2 ONTO ALL THE OTHER NEEDED ROWS
SH.Range("I2:I" & LR).FillDown
End If
End If

' FORMATS COLUMN I TO CURRENCY
Range("I:I").Select
Selection.NumberFormat = "#,##0.00"

Range("I1").Select
' STATUS BAR MESSAGE IS DEACTIVATED
Application.StatusBar = False

' TURNS SCREEN UPDATING ON
Application.ScreenUpdating = True

MsgBox "Report has been formatted!"

End Sub




 
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
Specify a row based on data from a cell to delete entire row..... Fadedmartinikiss Excel Discussion (Misc queries) 0 March 11th 09 08:39 PM
Delete an entire row One-Leg Excel Discussion (Misc queries) 13 November 11th 08 08:27 PM
Delete entire row if David T Excel Discussion (Misc queries) 2 December 6th 06 10:14 PM
Hide/Delete entire rows based in the content of one cell Clueless Excel Discussion (Misc queries) 2 October 3rd 05 02:40 PM
Delete entire row based on cell content PHIL Excel Programming 2 December 3rd 03 01:39 AM


All times are GMT +1. The time now is 05:46 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"