ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   deleting record with a range (https://www.excelbanter.com/excel-programming/407629-deleting-record-range.html)

[email protected]

deleting record with a range
 
I have a range of rows with data withi them. say 100 rows. on the
sheet theres acell in which you enter a number say 20. And the
program deletes all the rows within the range except the first 20, I
am using a very simple code at the moment but i am sure could be done
better

counter = Range("e11")
Range("e15").Select
Do Until countert = counter
ActiveCell.Offset(1, 0).Select
countert = countert + 1
Loop

Do Until ActiveCell = ""
ActiveCell.EntireRow.Delete
Loop

as you see the user determines the number of records he wants by
entering a number in range E11.

This does work fine but I am trying to learn better programming
methods where I am not actively moving around a worksheet, any
suggestions

Don Guillett

deleting record with a range
 
Try this. You could use x=inputbox("Enter num of rows") instead of a cell.

Sub delnumofrows()
x = Range("b1")
lr = Cells(Rows.Count, "a").End(xlUp).Row
If lr x Then Rows(x & ":" & lr).Delete
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

wrote in message
...
I have a range of rows with data withi them. say 100 rows. on the
sheet theres acell in which you enter a number say 20. And the
program deletes all the rows within the range except the first 20, I
am using a very simple code at the moment but i am sure could be done
better

counter = Range("e11")
Range("e15").Select
Do Until countert = counter
ActiveCell.Offset(1, 0).Select
countert = countert + 1
Loop

Do Until ActiveCell = ""
ActiveCell.EntireRow.Delete
Loop

as you see the user determines the number of records he wants by
entering a number in range E11.

This does work fine but I am trying to learn better programming
methods where I am not actively moving around a worksheet, any
suggestions



joel

deleting record with a range
 
counter = Range("e11")
FirstRow = 15
DeleteRow = FirstRow + counter
LastRow = Range("E" & Rows.Count).End(xlup).Row
rows(DeleteRow & ":" & Lastrow).Delete

" wrote:

I have a range of rows with data withi them. say 100 rows. on the
sheet theres acell in which you enter a number say 20. And the
program deletes all the rows within the range except the first 20, I
am using a very simple code at the moment but i am sure could be done
better

counter = Range("e11")
Range("e15").Select
Do Until countert = counter
ActiveCell.Offset(1, 0).Select
countert = countert + 1
Loop

Do Until ActiveCell = ""
ActiveCell.EntireRow.Delete
Loop

as you see the user determines the number of records he wants by
entering a number in range E11.

This does work fine but I am trying to learn better programming
methods where I am not actively moving around a worksheet, any
suggestions



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com