PC Review


Reply
Thread Tools Rate Thread

Delete rows macro

 
 
AshMorK
Guest
Posts: n/a
 
      29th Nov 2007
Hi all,

I looking for a macro that deletes a range when it find a text string in a
specific column. The macro must delete 2 rows after and 3 rows before the
founded range including it (6 entire rows ). the code I'm using only deletes
the row containing the founded text ("xxx"):

Sub deleterows()
Dim rngToSearch As Range
Dim wks As Worksheet
Dim rngFound As Range

Set wks = ActiveSheet
Set rngToSearch = wks.Columns(1)

Set rngFound = rngToSearch.Find("xxx")
If rngFound Is Nothing Then
MsgBox "No Deletions Found"
Else
Do
rngFound.EntireRow.Delete

Set rngFound = rngToSearch.FindNext
Loop Until rngFound Is Nothing
End If
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub

Thanks in advance for your help.
Ashmork
 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      29th Nov 2007
try
rngFound.Offset(-3).Resize(6).EntireRow.Delete

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"AshMorK" <(E-Mail Removed)> wrote in message
news:F9D5E8CC-ED2A-4FA5-B137-(E-Mail Removed)...
> Hi all,
>
> I looking for a macro that deletes a range when it find a text string in a
> specific column. The macro must delete 2 rows after and 3 rows before the
> founded range including it (6 entire rows ). the code I'm using only
> deletes
> the row containing the founded text ("xxx"):
>
> Sub deleterows()
> Dim rngToSearch As Range
> Dim wks As Worksheet
> Dim rngFound As Range
>
> Set wks = ActiveSheet
> Set rngToSearch = wks.Columns(1)
>
> Set rngFound = rngToSearch.Find("xxx")
> If rngFound Is Nothing Then
> MsgBox "No Deletions Found"
> Else
> Do
> rngFound.EntireRow.Delete
>
> Set rngFound = rngToSearch.FindNext
> Loop Until rngFound Is Nothing
> End If
> Application.ScreenUpdating = True
> Application.Calculation = xlCalculationAutomatic
> End Sub
>
> Thanks in advance for your help.
> Ashmork


 
Reply With Quote
 
AshMorK
Guest
Posts: n/a
 
      29th Nov 2007
Thanks Don! it works perfectly.

"Don Guillett" wrote:

> try
> rngFound.Offset(-3).Resize(6).EntireRow.Delete
>
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> (E-Mail Removed)
> "AshMorK" <(E-Mail Removed)> wrote in message
> news:F9D5E8CC-ED2A-4FA5-B137-(E-Mail Removed)...
> > Hi all,
> >
> > I looking for a macro that deletes a range when it find a text string in a
> > specific column. The macro must delete 2 rows after and 3 rows before the
> > founded range including it (6 entire rows ). the code I'm using only
> > deletes
> > the row containing the founded text ("xxx"):
> >
> > Sub deleterows()
> > Dim rngToSearch As Range
> > Dim wks As Worksheet
> > Dim rngFound As Range
> >
> > Set wks = ActiveSheet
> > Set rngToSearch = wks.Columns(1)
> >
> > Set rngFound = rngToSearch.Find("xxx")
> > If rngFound Is Nothing Then
> > MsgBox "No Deletions Found"
> > Else
> > Do
> > rngFound.EntireRow.Delete
> >
> > Set rngFound = rngToSearch.FindNext
> > Loop Until rngFound Is Nothing
> > End If
> > Application.ScreenUpdating = True
> > Application.Calculation = xlCalculationAutomatic
> > End Sub
> >
> > Thanks in advance for your help.
> > Ashmork

>
>

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      29th Nov 2007
Glad to help

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"AshMorK" <(E-Mail Removed)> wrote in message
news:A4ABB629-00AC-48F5-96AB-(E-Mail Removed)...
> Thanks Don! it works perfectly.
>
> "Don Guillett" wrote:
>
>> try
>> rngFound.Offset(-3).Resize(6).EntireRow.Delete
>>
>> --
>> Don Guillett
>> Microsoft MVP Excel
>> SalesAid Software
>> (E-Mail Removed)
>> "AshMorK" <(E-Mail Removed)> wrote in message
>> news:F9D5E8CC-ED2A-4FA5-B137-(E-Mail Removed)...
>> > Hi all,
>> >
>> > I looking for a macro that deletes a range when it find a text string
>> > in a
>> > specific column. The macro must delete 2 rows after and 3 rows before
>> > the
>> > founded range including it (6 entire rows ). the code I'm using only
>> > deletes
>> > the row containing the founded text ("xxx"):
>> >
>> > Sub deleterows()
>> > Dim rngToSearch As Range
>> > Dim wks As Worksheet
>> > Dim rngFound As Range
>> >
>> > Set wks = ActiveSheet
>> > Set rngToSearch = wks.Columns(1)
>> >
>> > Set rngFound = rngToSearch.Find("xxx")
>> > If rngFound Is Nothing Then
>> > MsgBox "No Deletions Found"
>> > Else
>> > Do
>> > rngFound.EntireRow.Delete
>> >
>> > Set rngFound = rngToSearch.FindNext
>> > Loop Until rngFound Is Nothing
>> > End If
>> > Application.ScreenUpdating = True
>> > Application.Calculation = xlCalculationAutomatic
>> > End Sub
>> >
>> > Thanks in advance for your help.
>> > Ashmork

>>
>>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to delete 2 rows every 500 rows beginner1.mat@hotmail.com Microsoft Excel Programming 3 3rd Feb 2008 01:52 PM
delete rows using macro nospam Microsoft Excel Worksheet Functions 5 20th Dec 2006 01:26 PM
Macro to delete all rows except rows that start $$11$ 11 Crowbar via OfficeKB.com Microsoft Excel Programming 7 23rd Oct 2005 04:30 PM
Macro to select 4 entire rows and then delete rows Scott Viney Microsoft Excel Discussion 3 22nd Sep 2005 07:02 PM
macro to delete entire rows when column A is blank ...a quick macro vikram Microsoft Excel Programming 4 3rd May 2004 08:45 PM


Features
 

Advertising
 

Newsgroups
 


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