PC Review


Reply
Thread Tools Rate Thread

deleting record with a range

 
 
john.9.williams@bt.com
Guest
Posts: n/a
 
      13th Mar 2008
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
 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      13th Mar 2008
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
(E-Mail Removed)
<(E-Mail Removed)> wrote in message
news:ac75e8e3-122a-4f4a-94bf-(E-Mail Removed)...
>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


 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      13th Mar 2008
counter = Range("e11")
FirstRow = 15
DeleteRow = FirstRow + counter
LastRow = Range("E" & Rows.Count).End(xlup).Row
rows(DeleteRow & ":" & Lastrow).Delete

"(E-Mail Removed)" 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
>

 
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
Deleting subform record causes form record to be deleted JerryD Microsoft Access Forms 0 12th Feb 2008 11:46 PM
convert range of numbers in one record into range of single-number records shadowsong@gmail.com Microsoft Access Queries 15 28th Jul 2007 02:39 AM
Deleting a duplicate record without deleting the data related. =?Utf-8?B?SGVhdGhlck1pY2hlbGxl?= Microsoft Access 3 12th Mar 2005 03:54 PM
permission denied when deleting record but record still deleted =?Utf-8?B?QW5uIFZsbmE=?= Microsoft Access 0 10th Dec 2004 04:45 PM
Deleting a record follow by Adding a record will result in getting wrong Index Key problem =?Utf-8?B?TGlzYSBKb25lcw==?= Microsoft VB .NET 0 30th Apr 2004 06:56 PM


Features
 

Advertising
 

Newsgroups
 


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