Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Delete Rows above keyword

I would like to use vba to delete all rows that are above
a certain keyword. Right now I have a macro that will
separate a customers PO by location but when it does, some
of the sheets have many blank rows at the top. The reason
that I would like it to find a keyword is because on some
of them, there is useless information within the blank
area. For example on one of the sheets, there maybe 10
blank rows, then in cell A1 there may be the word 'Car'
and then 10 more blank rows before cell A1 has the
customer information. I would like to be able to delete
all of the rows above the customer information. Hope that
makes sense. tia


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default Delete Rows above keyword

Brian,

Borrowed from Tom Olgivy.
Check the notes.
Test the code (code not tested)

Dim rng As Range
Dim rng1 As Range
Dim sStr As String
Set rng1 = Nothing
Set rng = Columns(1)
sStr = "ABCD"
' or use: sStr = inputbox("What to find")
Set rng1 = rng.Find(What:=sStr) ' change to suit your needs
If Not rng1 Is Nothing Then
Range(Rows(1), Rows(rng1.Row - 1)).Delete
Else
MsgBox "Not found"
End If

--
sb
"Brian" wrote in message
...
I would like to use vba to delete all rows that are above
a certain keyword. Right now I have a macro that will
separate a customers PO by location but when it does, some
of the sheets have many blank rows at the top. The reason
that I would like it to find a keyword is because on some
of them, there is useless information within the blank
area. For example on one of the sheets, there maybe 10
blank rows, then in cell A1 there may be the word 'Car'
and then 10 more blank rows before cell A1 has the
customer information. I would like to be able to delete
all of the rows above the customer information. Hope that
makes sense. tia




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Delete Rows above keyword

Steve,

do you know if there is a way to modify this so that if my
keyword happens to be in cell A1 the macro will not error
out?



-----Original Message-----
Brian,

Borrowed from Tom Olgivy.
Check the notes.
Test the code (code not tested)

Dim rng As Range
Dim rng1 As Range
Dim sStr As String
Set rng1 = Nothing
Set rng = Columns(1)
sStr = "ABCD"
' or use: sStr = inputbox("What to find")
Set rng1 = rng.Find(What:=sStr) ' change to suit your

needs
If Not rng1 Is Nothing Then
Range(Rows(1), Rows(rng1.Row - 1)).Delete
Else
MsgBox "Not found"
End If

--
sb
"Brian" wrote in message
...
I would like to use vba to delete all rows that are

above
a certain keyword. Right now I have a macro that will
separate a customers PO by location but when it does,

some
of the sheets have many blank rows at the top. The

reason
that I would like it to find a keyword is because on

some
of them, there is useless information within the blank
area. For example on one of the sheets, there maybe 10
blank rows, then in cell A1 there may be the word 'Car'
and then 10 more blank rows before cell A1 has the
customer information. I would like to be able to delete
all of the rows above the customer information. Hope

that
makes sense. tia




.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default Delete Rows above keyword

Brian,

Need to test row number by adding another if ....

Sorry I didn't catch that...

If rng1.row 1 then
Range(Rows(1), Rows(rng1.Row - 1)).Delete
End If


Dim rng As Range
Dim rng1 As Range
Dim sStr As String
Set rng1 = Nothing
Set rng = Columns(1)
sStr = "ABCD"
' or use: sStr = inputbox("What to find")
Set rng1 = rng.Find(What:=sStr) ' change to suit your needs
If Not rng1 Is Nothing Then
If rng1.row 1 then
Range(Rows(1), Rows(rng1.Row - 1)).Delete
End If
Else
MsgBox "Not found"
End If

--
sb
"Brian" wrote in message
...
Steve,

do you know if there is a way to modify this so that if my
keyword happens to be in cell A1 the macro will not error
out?



-----Original Message-----
Brian,

Borrowed from Tom Olgivy.
Check the notes.
Test the code (code not tested)

Dim rng As Range
Dim rng1 As Range
Dim sStr As String
Set rng1 = Nothing
Set rng = Columns(1)
sStr = "ABCD"
' or use: sStr = inputbox("What to find")
Set rng1 = rng.Find(What:=sStr) ' change to suit your

needs
If Not rng1 Is Nothing Then
Range(Rows(1), Rows(rng1.Row - 1)).Delete
Else
MsgBox "Not found"
End If

--
sb
"Brian" wrote in message
...
I would like to use vba to delete all rows that are

above
a certain keyword. Right now I have a macro that will
separate a customers PO by location but when it does,

some
of the sheets have many blank rows at the top. The

reason
that I would like it to find a keyword is because on

some
of them, there is useless information within the blank
area. For example on one of the sheets, there maybe 10
blank rows, then in cell A1 there may be the word 'Car'
and then 10 more blank rows before cell A1 has the
customer information. I would like to be able to delete
all of the rows above the customer information. Hope

that
makes sense. tia




.



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
delete a keyword from cells Shaz Excel Discussion (Misc queries) 3 April 16th 09 12:54 PM
Select rows based on keyword? Niniel Excel Discussion (Misc queries) 14 September 21st 07 08:18 PM
keyword search and delete row mikeyVo Excel Discussion (Misc queries) 2 August 1st 06 05:32 PM
Sort rows by keyword cww Excel Worksheet Functions 5 June 28th 06 02:48 AM
How to delete rows when List toolbar's "delete" isnt highlighted? Linda Excel Worksheet Functions 1 May 26th 05 08:39 PM


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