Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 347
Default delete from : to n rows after finding data in a cell

I want to find some text in col A and delete all rows until i find test in
col D.
e.g
find "Bank account name" in col A.
Then delete all rows down to "closing balance" in col d (do not delete Col d)
Any suggestions? cheers
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default delete from : to n rows after finding data in a cell

Do not delete column D--does that mean don't delete the row with closing balance
on it?

This seems to work ok for me:

Option Explicit
Sub testme()
Dim FoundCellTop As Range
Dim FoundCellBot As Range
Dim WhatToFindTop As String
Dim WhatToFindBot As String

WhatToFindTop = "Bank Account Name"
WhatToFindBot = "Closing Balance"

With Worksheets("sheet1")
With .Range("a:a")
Set FoundCellTop = .Cells.Find(what:=WhatToFindTop, _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
lookat:=xlWhole, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
End With

With .Range("d:d")
Set FoundCellBot = .Cells.Find(what:=WhatToFindBot, _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
lookat:=xlWhole, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
End With


If FoundCellTop Is Nothing _
Or FoundCellBot Is Nothing Then
MsgBox "At least one wasn't found!"
Exit Sub
End If

If (FoundCellBot.Row - FoundCellTop.Row) < 2 Then
MsgBox "nothing to delete"
Else
.Range(FoundCellTop.Offset(1, 0), _
FoundCellBot.Offset(-1, 0)).EntireRow.Delete
End If
End With

End Sub



George wrote:

I want to find some text in col A and delete all rows until i find test in
col D.
e.g
find "Bank account name" in col A.
Then delete all rows down to "closing balance" in col d (do not delete Col d)
Any suggestions? cheers


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 347
Default delete from : to n rows after finding data in a cell

Genius!
Thanks Dave

"Dave Peterson" wrote:

Do not delete column D--does that mean don't delete the row with closing balance
on it?

This seems to work ok for me:

Option Explicit
Sub testme()
Dim FoundCellTop As Range
Dim FoundCellBot As Range
Dim WhatToFindTop As String
Dim WhatToFindBot As String

WhatToFindTop = "Bank Account Name"
WhatToFindBot = "Closing Balance"

With Worksheets("sheet1")
With .Range("a:a")
Set FoundCellTop = .Cells.Find(what:=WhatToFindTop, _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
lookat:=xlWhole, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
End With

With .Range("d:d")
Set FoundCellBot = .Cells.Find(what:=WhatToFindBot, _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
lookat:=xlWhole, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
End With


If FoundCellTop Is Nothing _
Or FoundCellBot Is Nothing Then
MsgBox "At least one wasn't found!"
Exit Sub
End If

If (FoundCellBot.Row - FoundCellTop.Row) < 2 Then
MsgBox "nothing to delete"
Else
.Range(FoundCellTop.Offset(1, 0), _
FoundCellBot.Offset(-1, 0)).EntireRow.Delete
End If
End With

End Sub



George wrote:

I want to find some text in col A and delete all rows until i find test in
col D.
e.g
find "Bank account name" in col A.
Then delete all rows down to "closing balance" in col d (do not delete Col d)
Any suggestions? cheers


--

Dave Peterson

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 2003 Macro - Finding rows with data to copy Debbie Excel Worksheet Functions 1 March 23rd 10 01:23 PM
Finding data between blank rows j.ruderman[_2_] Excel Worksheet Functions 2 September 25th 08 11:48 AM
Finding common data in multiple columns and rows in Excel sparham Excel Worksheet Functions 3 February 12th 05 04:11 AM
Select rows after finding last cell Sam Fowler[_2_] Excel Programming 1 April 22nd 04 02:55 AM
Deleting rows A to E when finding dublicated Data in Column B bkbri[_3_] Excel Programming 6 December 15th 03 01:16 AM


All times are GMT +1. The time now is 09:05 AM.

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"