#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default VB question

I have a spreadsheet that has a column titled "Trans Code". This column is
one of 9 in the spreadsheet and is populated with one of the following, F800,
F900, F805 and F905. I want to delete all rows with F900, F805 and F905 and
keep only rows with F800 in that column. Can I accomplish this with VB code.
Also I only want to keep rows with todays date, I'm sure I can accomplish
this but just now sure how in Excel. Thank you.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default VB question

Try this

Sub FilterData()
Dim iLastRow As Long
Dim iLastCol As Long
Dim iTrans As Long, iDate As Long
Dim rng As Range

iTrans = Application.Match("Trans Code", Rows(1), 0)
iDate = Application.Match("Date", Rows(1), 0)
iLastCol = Cells(1, Columns.Count).End(xlToLeft).Column
iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
Columns(1).Insert
Set rng = Range("A2").Resize(iLastRow)
Range("A2").FormulaR1C1 = "=OR(RC" & iDate + 1 & "=TODAY(),RC" & _
iTrans + 1 & "=""F800"")"
Range("A2").AutoFill Range("A2").Resize(iLastRow - 1)
rng.AutoFilter field:=1, Criteria1:=False
rng.SpecialCells(xlCellTypeVisible).EntireRow.Dele te
Columns(1).Delete
End Sub


--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"JOUIOUI" wrote in message
...
I have a spreadsheet that has a column titled "Trans Code". This column

is
one of 9 in the spreadsheet and is populated with one of the following,

F800,
F900, F805 and F905. I want to delete all rows with F900, F805 and F905

and
keep only rows with F800 in that column. Can I accomplish this with VB

code.
Also I only want to keep rows with todays date, I'm sure I can accomplish
this but just now sure how in Excel. Thank you.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default VB question

Thanks so much for your assistance Bob....the code runs fine until it gets to
this part of the code:

Range("A2").AutoFill Range("A2").Resize(iLastRow - 1)

I'm set to take a VBA class in 3 weeks but until then this is all way to
complex for me. Any help you can provide is appreciated.

Thanks
Joyce

"Bob Phillips" wrote:

Try this

Sub FilterData()
Dim iLastRow As Long
Dim iLastCol As Long
Dim iTrans As Long, iDate As Long
Dim rng As Range

iTrans = Application.Match("Trans Code", Rows(1), 0)
iDate = Application.Match("Date", Rows(1), 0)
iLastCol = Cells(1, Columns.Count).End(xlToLeft).Column
iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
Columns(1).Insert
Set rng = Range("A2").Resize(iLastRow)
Range("A2").FormulaR1C1 = "=OR(RC" & iDate + 1 & "=TODAY(),RC" & _
iTrans + 1 & "=""F800"")"
Range("A2").AutoFill Range("A2").Resize(iLastRow - 1)
rng.AutoFilter field:=1, Criteria1:=False
rng.SpecialCells(xlCellTypeVisible).EntireRow.Dele te
Columns(1).Delete
End Sub


--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"JOUIOUI" wrote in message
...
I have a spreadsheet that has a column titled "Trans Code". This column

is
one of 9 in the spreadsheet and is populated with one of the following,

F800,
F900, F805 and F905. I want to delete all rows with F900, F805 and F905

and
keep only rows with F800 in that column. Can I accomplish this with VB

code.
Also I only want to keep rows with todays date, I'm sure I can accomplish
this but just now sure how in Excel. Thank you.




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
Excel 2007 Macro/VB Question DDE Question MadDog22 Excel Worksheet Functions 1 March 10th 10 01:47 AM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good davegb Excel Programming 1 May 6th 05 06:35 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 0 April 27th 05 07:46 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 23 April 23rd 05 09:26 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 0 April 22nd 05 03:30 PM


All times are GMT +1. The time now is 12:54 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"