#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Delete Rows

Hi, I am in need of a piece of code that can delete all rows downwards from
10 rows below a value in column K
For example, If the cell K2050 contained a value, I want the code to delete
all rows from Cell K2060 downwards. Columns either side of the Value have
formulas that run down to 3000 rows and that is why I need to concentrate on
column K.
Help greatly appreciated
Kind Regards
John

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Delete Rows

Sub RowKiller()
Dim r1 As Range, r2 As Range
Dim n As Long
n = 2050
m = n + 10
Set r1 = Range("K" & n)
Set r2 = Range("K" & m & ":K" & Rows.Count)
If r1.Value < "" Then
r2.EntireRow.Delete
End If
End Sub

--
Gary''s Student - gsnu200837
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Delete Rows

Hi Gary, Many thanks for your help. What I should have mentioned was that the
values fluctuate between 1000 and 3000 rows, whereas your code is specific.
Is there some way of changing the code so that it will delete from the tenth
row below the value where ever it ends in column K?
This piece of code is one that Chip Pearson kindly done for me some time ago
that I modified slightly, but I still cant get it to work for my needs
because it ends up deleting the last row of data (If it helps)

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
Exit Sub
End If
With ActiveSheet
Set LastCell = .Cells(.Rows.count, WHAT_COLUMN).End(xlUp)
.Range(FoundCell(3000, 1), LastCell).EntireRow.Delete
End With
End Sub

Thanks
John


"Gary''s Student" wrote:

Sub RowKiller()
Dim r1 As Range, r2 As Range
Dim n As Long
n = 2050
m = n + 10
Set r1 = Range("K" & n)
Set r2 = Range("K" & m & ":K" & Rows.Count)
If r1.Value < "" Then
r2.EntireRow.Delete
End If
End Sub

--
Gary''s Student - gsnu200837

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Delete Rows

This version will first locate the last filled in in column K, go do the 10
rows and the do the delete:

Sub RowKiller()
Dim r1 As Range, r2 As Range
Dim n As Long
n = Cells(Rows.Count, "K").End(xlUp).Row
m = n + 10
Set r1 = Range("K" & n)
Set r2 = Range("K" & m & ":K" & Rows.Count)
If r1.Value < "" Then
r2.EntireRow.Delete
End If
End Sub

So if K4 is the last filled cell in column K, then rows 14 on down will be
deleted.
--
Gary''s Student - gsnu200837


"JohnUK" wrote:

Hi Gary, Many thanks for your help. What I should have mentioned was that the
values fluctuate between 1000 and 3000 rows, whereas your code is specific.
Is there some way of changing the code so that it will delete from the tenth
row below the value where ever it ends in column K?
This piece of code is one that Chip Pearson kindly done for me some time ago
that I modified slightly, but I still cant get it to work for my needs
because it ends up deleting the last row of data (If it helps)

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
Exit Sub
End If
With ActiveSheet
Set LastCell = .Cells(.Rows.count, WHAT_COLUMN).End(xlUp)
.Range(FoundCell(3000, 1), LastCell).EntireRow.Delete
End With
End Sub

Thanks
John


"Gary''s Student" wrote:

Sub RowKiller()
Dim r1 As Range, r2 As Range
Dim n As Long
n = 2050
m = n + 10
Set r1 = Range("K" & n)
Set r2 = Range("K" & m & ":K" & Rows.Count)
If r1.Value < "" Then
r2.EntireRow.Delete
End If
End Sub

--
Gary''s Student - gsnu200837

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Delete Rows

Gary - You are a star *
Many thanks, it worked a treat. You dont know how long I have been putting
up with this problem!!
Take care
Best Regards
John

"Gary''s Student" wrote:

This version will first locate the last filled in in column K, go do the 10
rows and the do the delete:

Sub RowKiller()
Dim r1 As Range, r2 As Range
Dim n As Long
n = Cells(Rows.Count, "K").End(xlUp).Row
m = n + 10
Set r1 = Range("K" & n)
Set r2 = Range("K" & m & ":K" & Rows.Count)
If r1.Value < "" Then
r2.EntireRow.Delete
End If
End Sub

So if K4 is the last filled cell in column K, then rows 14 on down will be
deleted.
--
Gary''s Student - gsnu200837


"JohnUK" wrote:

Hi Gary, Many thanks for your help. What I should have mentioned was that the
values fluctuate between 1000 and 3000 rows, whereas your code is specific.
Is there some way of changing the code so that it will delete from the tenth
row below the value where ever it ends in column K?
This piece of code is one that Chip Pearson kindly done for me some time ago
that I modified slightly, but I still cant get it to work for my needs
because it ends up deleting the last row of data (If it helps)

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
Exit Sub
End If
With ActiveSheet
Set LastCell = .Cells(.Rows.count, WHAT_COLUMN).End(xlUp)
.Range(FoundCell(3000, 1), LastCell).EntireRow.Delete
End With
End Sub

Thanks
John


"Gary''s Student" wrote:

Sub RowKiller()
Dim r1 As Range, r2 As Range
Dim n As Long
n = 2050
m = n + 10
Set r1 = Range("K" & n)
Set r2 = Range("K" & m & ":K" & Rows.Count)
If r1.Value < "" Then
r2.EntireRow.Delete
End If
End Sub

--
Gary''s Student - gsnu200837



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Delete Rows

Thank you for the feedback!
--
Gary''s Student - gsnu200837


"JohnUK" wrote:

Gary - You are a star *
Many thanks, it worked a treat. You dont know how long I have been putting
up with this problem!!
Take care
Best Regards
John

"Gary''s Student" wrote:

This version will first locate the last filled in in column K, go do the 10
rows and the do the delete:

Sub RowKiller()
Dim r1 As Range, r2 As Range
Dim n As Long
n = Cells(Rows.Count, "K").End(xlUp).Row
m = n + 10
Set r1 = Range("K" & n)
Set r2 = Range("K" & m & ":K" & Rows.Count)
If r1.Value < "" Then
r2.EntireRow.Delete
End If
End Sub

So if K4 is the last filled cell in column K, then rows 14 on down will be
deleted.
--
Gary''s Student - gsnu200837


"JohnUK" wrote:

Hi Gary, Many thanks for your help. What I should have mentioned was that the
values fluctuate between 1000 and 3000 rows, whereas your code is specific.
Is there some way of changing the code so that it will delete from the tenth
row below the value where ever it ends in column K?
This piece of code is one that Chip Pearson kindly done for me some time ago
that I modified slightly, but I still cant get it to work for my needs
because it ends up deleting the last row of data (If it helps)

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
Exit Sub
End If
With ActiveSheet
Set LastCell = .Cells(.Rows.count, WHAT_COLUMN).End(xlUp)
.Range(FoundCell(3000, 1), LastCell).EntireRow.Delete
End With
End Sub

Thanks
John


"Gary''s Student" wrote:

Sub RowKiller()
Dim r1 As Range, r2 As Range
Dim n As Long
n = 2050
m = n + 10
Set r1 = Range("K" & n)
Set r2 = Range("K" & m & ":K" & Rows.Count)
If r1.Value < "" Then
r2.EntireRow.Delete
End If
End Sub

--
Gary''s Student - gsnu200837

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
Delete Rows if any cell in Column H is blank but do not Delete Fir manfareed Excel Programming 4 September 28th 07 05:20 PM
Copy pasting Rows, but need to Delete any Shapes/Pictures that are within copied rows Corey Excel Programming 2 August 1st 07 02:02 AM
Cut filtered rows, paste into next empty row of new sheet, and delete cut rows Scott Excel Worksheet Functions 0 December 13th 06 01:25 AM
How to delete rows when List toolbar's "delete" isnt highlighted? Linda Excel Worksheet Functions 1 May 26th 05 08:39 PM
Delete every 3rd row, then delete rows 2-7, move info f/every 2nd row up one to the end and delete the row below Annette[_4_] Excel Programming 2 September 21st 04 02:40 PM


All times are GMT +1. The time now is 10:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"