PC Review


Reply
Thread Tools Rate Thread

Delete Multiple Rows in one go

 
 
JohnUK
Guest
Posts: n/a
 
      14th Jan 2009
Hi, Can anyone help with this. I need a piece of code that can delete all
rows in one swoop, working from the last/end row to the 10th row below a
given column with values in it. I hope I explained that okay. Help greatly
appreciated
John
 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      14th Jan 2009
Always best to fully explain.

Say col B??
clear all rows from 11 to 30 if 30 is the last row, or 29 if 30 is the last
row
OR, clear only blanks in that area

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"JohnUK" <(E-Mail Removed)> wrote in message
news:A2A42EE1-A889-47DA-B242-(E-Mail Removed)...
> Hi, Can anyone help with this. I need a piece of code that can delete all
> rows in one swoop, working from the last/end row to the 10th row below a
> given column with values in it. I hope I explained that okay. Help greatly
> appreciated
> John


 
Reply With Quote
 
JohnUK
Guest
Posts: n/a
 
      14th Jan 2009
Thanks Don,
Because I have formulas that run down the sides and in between Values
(Values can vary between 1000 to 2800 rows and the formulas run down to 3000
rows, I need the code to delete (All) the rows from 10 rows below the values
that sits in column "K".
Reason I need the code:
Template picks up data from another workbook, then saves as something else,
the code then tidies up (Deletes excess rows) close, re-opens to start the
process over again. I have tried the delete one row at a time option but end
up waiting forever. By using the Clear instead of delete, made it a bit
faster but the file is still left with Ranges that run down to the 3000th
row, that’s why I need the code to delete in bulk.
Regards
John


"Don Guillett" wrote:

> Always best to fully explain.
>
> Say col B??
> clear all rows from 11 to 30 if 30 is the last row, or 29 if 30 is the last
> row
> OR, clear only blanks in that area
>
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> (E-Mail Removed)
> "JohnUK" <(E-Mail Removed)> wrote in message
> news:A2A42EE1-A889-47DA-B242-(E-Mail Removed)...
> > Hi, Can anyone help with this. I need a piece of code that can delete all
> > rows in one swoop, working from the last/end row to the 10th row below a
> > given column with values in it. I hope I explained that okay. Help greatly
> > appreciated
> > John

>
>

 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      14th Jan 2009
Try something like the following:

Sub AAA()
Const WHAT_COLUMN = "A"
Dim LastCell As Range
Dim FoundCell As Range

Set FoundCell = ActiveSheet.UsedRange.Find("abc")
If FoundCell Is Nothing Then
' not found. get out.
Exit Sub
End If
With ActiveSheet
Set LastCell = .Cells(.Rows.Count, WHAT_COLUMN).End(xlUp)
.Range(FoundCell(11, 1), LastCell).EntireRow.Delete
End With
End Sub

Change WHAT_COLUMN to the column in which the specified value ("abc"
in this example) is to be found.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Wed, 14 Jan 2009 10:15:01 -0800, JohnUK
<(E-Mail Removed)> wrote:

>Hi, Can anyone help with this. I need a piece of code that can delete all
>rows in one swoop, working from the last/end row to the 10th row below a
>given column with values in it. I hope I explained that okay. Help greatly
>appreciated
>John

 
Reply With Quote
 
JohnUK
Guest
Posts: n/a
 
      14th Jan 2009
Hi Chip, Tried your code, but still not what I need. See my previous post.
Many thanks though. Kind Regards, John

"Chip Pearson" wrote:

> Try something like the following:
>
> Sub AAA()
> Const WHAT_COLUMN = "A"
> Dim LastCell As Range
> Dim FoundCell As Range
>
> Set FoundCell = ActiveSheet.UsedRange.Find("abc")
> If FoundCell Is Nothing Then
> ' not found. get out.
> Exit Sub
> End If
> With ActiveSheet
> Set LastCell = .Cells(.Rows.Count, WHAT_COLUMN).End(xlUp)
> .Range(FoundCell(11, 1), LastCell).EntireRow.Delete
> End With
> End Sub
>
> Change WHAT_COLUMN to the column in which the specified value ("abc"
> in this example) is to be found.
>
> Cordially,
> Chip Pearson
> Microsoft Most Valuable Professional
> Excel Product Group
> Pearson Software Consulting, LLC
> www.cpearson.com
> (email on web site)
>
>
> On Wed, 14 Jan 2009 10:15:01 -0800, JohnUK
> <(E-Mail Removed)> wrote:
>
> >Hi, Can anyone help with this. I need a piece of code that can delete all
> >rows in one swoop, working from the last/end row to the 10th row below a
> >given column with values in it. I hope I explained that okay. Help greatly
> >appreciated
> >John

>

 
Reply With Quote
 
JohnUK
Guest
Posts: n/a
 
      10th Mar 2009
Hi Chip,
I am having another go at this.
I have modified your code slightly:

Sub AAA()
Const WHAT_COLUMN = "k"
Dim LastCell As Range
Dim FoundCell As Range

Set FoundCell = ActiveSheet.UsedRange.Find("k")
If FoundCell Is Nothing Then
' not found. get out.
Exit Sub
End If
With ActiveSheet
Set LastCell = .Cells(.Rows.count, WHAT_COLUMN).End(xlUp)
.Range(FoundCell(2000, 1), LastCell).EntireRow.Delete
End With
End Sub

It works appart from it deletes the last row of data.
Is there some sort of an offset (Have I got that right) so that it wont
delete the last so many rows below the last value (10 rows for example)?

Many thanks

John





"Chip Pearson" wrote:

> Try something like the following:
>
> Sub AAA()
> Const WHAT_COLUMN = "A"
> Dim LastCell As Range
> Dim FoundCell As Range
>
> Set FoundCell = ActiveSheet.UsedRange.Find("abc")
> If FoundCell Is Nothing Then
> ' not found. get out.
> Exit Sub
> End If
> With ActiveSheet
> Set LastCell = .Cells(.Rows.Count, WHAT_COLUMN).End(xlUp)
> .Range(FoundCell(11, 1), LastCell).EntireRow.Delete
> End With
> End Sub
>
> Change WHAT_COLUMN to the column in which the specified value ("abc"
> in this example) is to be found.
>
> Cordially,
> Chip Pearson
> Microsoft Most Valuable Professional
> Excel Product Group
> Pearson Software Consulting, LLC
> www.cpearson.com
> (email on web site)
>
>
> On Wed, 14 Jan 2009 10:15:01 -0800, JohnUK
> <(E-Mail Removed)> wrote:
>
> >Hi, Can anyone help with this. I need a piece of code that can delete all
> >rows in one swoop, working from the last/end row to the 10th row below a
> >given column with values in it. I hope I explained that okay. Help greatly
> >appreciated
> >John

>

 
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
Hpw do I delete multiple empty rows found between filled rows? Bill Microsoft Excel Worksheet Functions 1 15th Nov 2009 12:52 AM
Delete Blank Rows Code - Multiple Worksheets - Multiple Documents =?Utf-8?B?QmVuUw==?= Microsoft Excel Misc 3 29th Jun 2007 12:20 AM
delete multiple rows =?Utf-8?B?d2poNTk=?= Microsoft Word Document Management 4 18th Nov 2005 04:09 PM
How to delete multiple rows bazish Microsoft Excel Worksheet Functions 3 15th Aug 2003 09:06 PM
What is the best way to delete multiple rows Terry Burns Microsoft ADO .NET 1 14th Aug 2003 05:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:07 AM.