#1   Report Post  
Farooq Sheri
 
Posts: n/a
Default Want to delete rows

I have text file which I import into Excel. There is a particular string
which I need to find (this can be in any row) so the row position is
variable. I can find this string no problem. What I want to do is once I find
the string, then starting from the row where the string is located, I want to
delete all rows above including the row in which the desired string is
located.

e.g the string is at Row 27, delete rows 1-27.

Thanks
  #2   Report Post  
Shatin
 
Posts: n/a
Default

So you first find the string. Once the string is found, you press CTRL-SHIFT
and the UP ARROW keys. This will select all the cells in the column up to
the cell where the search string is in. Once you've done that, you choose
EditDeleteEntire row.

Or if what you mean is you have to repeat this process with many files, then
you use following VBA code:

Sub deleteRows()
Dim dString As String
Dim rng As Range
dString = InputBox("Please enter the search string.")
Set rng = ActiveSheet.UsedRange.Find(dString)
If Not rng Is Nothing Then
Range(rng, rng.End(xlUp)).EntireRow.Delete
Else
MsgBox ("Make sure you enter the correct string!")
End If
End Sub

"Farooq Sheri" wrote in message
...
I have text file which I import into Excel. There is a particular string
which I need to find (this can be in any row) so the row position is
variable. I can find this string no problem. What I want to do is once I

find
the string, then starting from the row where the string is located, I want

to
delete all rows above including the row in which the desired string is
located.

e.g the string is at Row 27, delete rows 1-27.

Thanks



  #3   Report Post  
Dave Peterson
 
Posts: n/a
Default

Manually???

Just find that troublesome word
then hit ctrl-shift-home
then Edit|Delete...|Entire row



Farooq Sheri wrote:

I have text file which I import into Excel. There is a particular string
which I need to find (this can be in any row) so the row position is
variable. I can find this string no problem. What I want to do is once I find
the string, then starting from the row where the string is located, I want to
delete all rows above including the row in which the desired string is
located.

e.g the string is at Row 27, delete rows 1-27.

Thanks


--

Dave Peterson
  #4   Report Post  
Farooq Sheri
 
Posts: n/a
Default

Thanks for the response. Doing it manually is trivial. What I wanted was a
VBA code which you have provided. I have used it in my Excel sheet but it
only deletes the enitre row which contains the string. I also want to delete
all rows above it. e.g if row 7 contains the string I want to delete rows 1-7

"Shatin" wrote:

So you first find the string. Once the string is found, you press CTRL-SHIFT
and the UP ARROW keys. This will select all the cells in the column up to
the cell where the search string is in. Once you've done that, you choose
EditDeleteEntire row.

Or if what you mean is you have to repeat this process with many files, then
you use following VBA code:

Sub deleteRows()
Dim dString As String
Dim rng As Range
dString = InputBox("Please enter the search string.")
Set rng = ActiveSheet.UsedRange.Find(dString)
If Not rng Is Nothing Then
Range(rng, rng.End(xlUp)).EntireRow.Delete
Else
MsgBox ("Make sure you enter the correct string!")
End If
End Sub

"Farooq Sheri" wrote in message
...
I have text file which I import into Excel. There is a particular string
which I need to find (this can be in any row) so the row position is
variable. I can find this string no problem. What I want to do is once I

find
the string, then starting from the row where the string is located, I want

to
delete all rows above including the row in which the desired string is
located.

e.g the string is at Row 27, delete rows 1-27.

Thanks




  #5   Report Post  
Rowan
 
Posts: n/a
Default

Replace the line:

Range(rng, rng.End(xlUp)).EntireRow.Delete
with
Rows("1:" & rng.Row).Delete

Hope this helps
Rowan

Farooq Sheri wrote:
Thanks for the response. Doing it manually is trivial. What I wanted was a
VBA code which you have provided. I have used it in my Excel sheet but it
only deletes the enitre row which contains the string. I also want to delete
all rows above it. e.g if row 7 contains the string I want to delete rows 1-7

"Shatin" wrote:


So you first find the string. Once the string is found, you press CTRL-SHIFT
and the UP ARROW keys. This will select all the cells in the column up to
the cell where the search string is in. Once you've done that, you choose
EditDeleteEntire row.

Or if what you mean is you have to repeat this process with many files, then
you use following VBA code:

Sub deleteRows()
Dim dString As String
Dim rng As Range
dString = InputBox("Please enter the search string.")
Set rng = ActiveSheet.UsedRange.Find(dString)
If Not rng Is Nothing Then
Range(rng, rng.End(xlUp)).EntireRow.Delete
Else
MsgBox ("Make sure you enter the correct string!")
End If
End Sub

"Farooq Sheri" wrote in message
...

I have text file which I import into Excel. There is a particular string
which I need to find (this can be in any row) so the row position is
variable. I can find this string no problem. What I want to do is once I


find

the string, then starting from the row where the string is located, I want


to

delete all rows above including the row in which the desired string is
located.

e.g the string is at Row 27, delete rows 1-27.

Thanks






  #6   Report Post  
Farooq Sheri
 
Posts: n/a
Default

One thing that I just noted is that your code stops at the first empty row it
encounters deleting upwards. For example the string is at row 7. Row 4 is an
empty row (no data). Your code will delete rows 5-7 but will stop at row 4. I
think it has some thing to do with the way you have constructed your If
statement.

Thanks
Farooq

"Shatin" wrote:

So you first find the string. Once the string is found, you press CTRL-SHIFT
and the UP ARROW keys. This will select all the cells in the column up to
the cell where the search string is in. Once you've done that, you choose
EditDeleteEntire row.

Or if what you mean is you have to repeat this process with many files, then
you use following VBA code:

Sub deleteRows()
Dim dString As String
Dim rng As Range
dString = InputBox("Please enter the search string.")
Set rng = ActiveSheet.UsedRange.Find(dString)
If Not rng Is Nothing Then
Range(rng, rng.End(xlUp)).EntireRow.Delete
Else
MsgBox ("Make sure you enter the correct string!")
End If
End Sub

"Farooq Sheri" wrote in message
...
I have text file which I import into Excel. There is a particular string
which I need to find (this can be in any row) so the row position is
variable. I can find this string no problem. What I want to do is once I

find
the string, then starting from the row where the string is located, I want

to
delete all rows above including the row in which the desired string is
located.

e.g the string is at Row 27, delete rows 1-27.

Thanks




  #7   Report Post  
Farooq Sheri
 
Posts: n/a
Default

It sure does help. Thanks.

Farooq

"Rowan" wrote:

Replace the line:

Range(rng, rng.End(xlUp)).EntireRow.Delete
with
Rows("1:" & rng.Row).Delete

Hope this helps
Rowan

Farooq Sheri wrote:
Thanks for the response. Doing it manually is trivial. What I wanted was a
VBA code which you have provided. I have used it in my Excel sheet but it
only deletes the enitre row which contains the string. I also want to delete
all rows above it. e.g if row 7 contains the string I want to delete rows 1-7

"Shatin" wrote:


So you first find the string. Once the string is found, you press CTRL-SHIFT
and the UP ARROW keys. This will select all the cells in the column up to
the cell where the search string is in. Once you've done that, you choose
EditDeleteEntire row.

Or if what you mean is you have to repeat this process with many files, then
you use following VBA code:

Sub deleteRows()
Dim dString As String
Dim rng As Range
dString = InputBox("Please enter the search string.")
Set rng = ActiveSheet.UsedRange.Find(dString)
If Not rng Is Nothing Then
Range(rng, rng.End(xlUp)).EntireRow.Delete
Else
MsgBox ("Make sure you enter the correct string!")
End If
End Sub

"Farooq Sheri" wrote in message
...

I have text file which I import into Excel. There is a particular string
which I need to find (this can be in any row) so the row position is
variable. I can find this string no problem. What I want to do is once I

find

the string, then starting from the row where the string is located, I want

to

delete all rows above including the row in which the desired string is
located.

e.g the string is at Row 27, delete rows 1-27.

Thanks




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
How can we delete rows permanently from excel sheet Nehal Shah Excel Discussion (Misc queries) 1 August 1st 05 01:58 PM
In a protected worksheet allow users to delete rows Jason Trivett Excel Worksheet Functions 1 July 12th 05 09:50 AM
How do I find duplicate rows in a list in Excel, and not delete it Matthew in FL Excel Discussion (Misc queries) 2 June 15th 05 09:11 PM
Protect Worksheet but allow to insert or delete rows Bob L Hilliard Excel Discussion (Misc queries) 2 June 9th 05 02:08 PM
How to delete blank rows John Mansfield Excel Discussion (Misc queries) 3 April 27th 05 11:48 PM


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