Vba to delete data between 2 found address:

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Hi, I need Vba to delete data between 2 found address:
Suppose I want to look through all range from A1:A and lastrow. from top or back loop from bottom row...
I want to find "Critiria 1 word" and then
I want to find "Critiria 2 word"
I want to delete all the words that comes between it...

Is this possible?
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
There is probably a more elegant way to do this but this is what my sleep deprived brain came up with.

Code:
Sub deleterange()
Dim iFind As Range, uFind As Range
Dim lastrow As Long
 
lastrow = Range("A" & Rows.Count).End(xlUp).Row
 
Set iFind = Range("A1:A" & lastrow).Find(What:="this", LookIn:=xlValues, LookAt:=xlWhole)
Set uFind = Range("A1:A" & lastrow).Find(What:="test", LookIn:=xlValues, LookAt:=xlWhole)
 
Range("A" & iFind.Row + 1, "A" & uFind.Row - 1).ClearContents
End Sub
 
Upvote 0
does this work

Code:
Sub DeleteCriteria()
Dim Crit1 As String, Crit2 As String
Dim rFound As Variant, rFound2 As Variant
Crit1 = InputBox("Enter 1st Word of area to delete")
Crit2 = InputBox("Enter 2nd Word of area to delete")
    Set rFound = Columns(1).Find(What:=Crit1 & i, LookIn:=xlValues, LookAt:= _
        xlPart, SearchOrder:=xlByRows, MatchCase:=False _
        , SearchFormat:=False)
    If rFound Is Nothing Then GoTo 0
    rFound.Activate
    rFound.Address
    Set rFound2 = Columns(1).Find(What:=Crit2 & i, LookIn:=xlValues, LookAt:= _
        xlPart, SearchOrder:=xlByRows, MatchCase:=False _
        , SearchFormat:=False)
    If rFound Is Nothing Then GoTo 0
    rFound2.Activate
    rFound2.Address
Range(rFound & ":" & rFound2).Delete
0
End Sub

note: untested
 
Upvote 0
Maybe

Code:
Sub Pedie()
Dim F1 As Range, F2 As Range
Set F1 = Columns("A").Find(what:="Critiria 1 word", LookIn:=xlValues, LookIn:=xlWhole)
Set F2 = Columns("A").Find(what:="Critiria 2 word", LookIn:=xlValues, LookIn:=xlWhole)
Range(Cells(F1, 1), Cells(F2, 1)).EntireRow.Delete
End Sub
 
Upvote 0
All of it worked for one range only...i want to keep searching till the word is no more...from Row 1 till last row...

I have group of similiar datas but dont need most of it...so i want to find the words remove the rows including the found row/address...

Thanks again.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,712
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top