PC Review


Reply
 
 
helene and gabor
Guest
Posts: n/a
 
      13th May 2010
Hello,

My simple program would make me believe that all rows 1 to 16 will be
deleted.
Not so. Only the odd numbered entries in col.A got deleted, entries
2,4,6,....16 remained.
My simple program is this:
------------------------------------------------------------------------------

Sub deleterows()
Dim i As Long
For i = 1 To 16
Rows(i).Delete
Next i
End Sub

--------------------------------------------------------------------------------
Thanks for your help.

Regards,

Gabor Sebo

 
Reply With Quote
 
 
 
 
Wouter HM
Guest
Posts: n/a
 
      13th May 2010
Hi Gabor,

When yor delete rows in this order the row counter gets mixed up.
As soon as the first row is deleted the second row becomes the 'new'
first row.
And so on.
So to remove rows using a for-next loop use:

Sub deleterows()
Dim i As Long
For i = 16 To 1 Step -1
Rows(i).Delete
Next i
End Sub


HTH,

Wouter
 
Reply With Quote
 
Project Mangler
Guest
Posts: n/a
 
      13th May 2010
Gabor,

To see why try:

Sub deleterows()
Dim i As Long
For i = 16 To 1 Step -1
Rows(i).Delete
Next i
End Sub


"helene and gabor" <(E-Mail Removed)> wrote in message
news:FF22C6F5-32EB-4C60-B272-(E-Mail Removed)...
> Hello,
>
> My simple program would make me believe that all rows 1 to 16 will be
> deleted.
> Not so. Only the odd numbered entries in col.A got deleted, entries
> 2,4,6,....16 remained.
> My simple program is this:
> --------------------------------------------------------------------------

----
>
> Sub deleterows()
> Dim i As Long
> For i = 1 To 16
> Rows(i).Delete
> Next i
> End Sub
>
> --------------------------------------------------------------------------

------
> Thanks for your help.
>
> Regards,
>
> Gabor Sebo
>



 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      13th May 2010
But if you wanted, you could take advantage of what excel did:

Sub deleterows()
Dim i As Long
For i = 1 To 16
Rows(1).Delete
Next i
End Sub

It's always deleting row 1 and shifting rows up.

You could use:
rows(1 & ":" & 16).delete
or
rows("1:16").delete
or
range("A1").resize(16,1).entirerow.delete

=========
But I expect that you're doing more than just deleting 16 rows. I bet you're
using some criteria to determine if you should delete the row.

You could use:

Dim myCell as range
dim myRng as range
dim delRng as range

with worksheets("Somesheetnamehere")
set myrng = .range("A1", .cells(.rows.count,"A").end(xlup))
end with

for each mycell in myrng.cells
if lcase(left(mycell.value,1)) = lcase("u") then
'keep it
else
if delrng is nothing then
set delrng = mycell
else
set delrng = union(mycell, delrng)
end if
end if
next mycell

if delrng is nothing then
'nothing to delete
else
delrng.entirerow.delete
end if


helene and gabor wrote:

> Hello,
>
> My simple program would make me believe that all rows 1 to 16 will be
> deleted.
> Not so. Only the odd numbered entries in col.A got deleted, entries
> 2,4,6,....16 remained.
> My simple program is this:
> ------------------------------------------------------------------------------
>
>
> Sub deleterows()
> Dim i As Long
> For i = 1 To 16
> Rows(i).Delete
> Next i
> End Sub
>
> --------------------------------------------------------------------------------
>
> Thanks for your help.
>
> Regards,
>
> Gabor Sebo


--

Dave Peterson
 
Reply With Quote
 
helene and gabor
Guest
Posts: n/a
 
      13th May 2010
Hello all responders to my problem,

Your replies are logical and clear. I tried to respond to someone's problem:
Delete all rows below cell that has:" False" in it.
I now find the row number for the word :False, and delete lines from upper
limit to this row number step - 1.

Thanks very much!

Gabor Sebo

------------------------------------------------------------------------------------------------------------------------------------------------------------------




"helene and gabor" <(E-Mail Removed)> wrote in message
news:FF22C6F5-32EB-4C60-B272-(E-Mail Removed)...
> Hello,
>
> My simple program would make me believe that all rows 1 to 16 will be
> deleted.
> Not so. Only the odd numbered entries in col.A got deleted, entries
> 2,4,6,....16 remained.
> My simple program is this:
> ------------------------------------------------------------------------------
>
> Sub deleterows()
> Dim i As Long
> For i = 1 To 16
> Rows(i).Delete
> Next i
> End Sub
>
> --------------------------------------------------------------------------------
> Thanks for your help.
>
> Regards,
>
> Gabor Sebo
>


 
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
Autofil on variable rows, delete extract and show remaining rows 1plane Microsoft Excel Programming 3 17th Nov 2009 10:49 AM
Hpw do I delete multiple empty rows found between filled rows? Bill Microsoft Excel Worksheet Functions 1 15th Nov 2009 12:52 AM
Copy pasting Rows, but need to Delete any Shapes/Pictures that are within copied rows Corey Microsoft Excel Programming 2 1st Aug 2007 02:02 AM
Cut filtered rows, paste into next empty row of new sheet, and delete cut rows Scott Microsoft Excel Worksheet Functions 0 13th Dec 2006 01:25 AM
Delete rows with numeric values, leave rows with text =?Utf-8?B?R1NwbGluZQ==?= Microsoft Excel Programming 5 11th Oct 2005 12:44 AM


Features
 

Advertising
 

Newsgroups
 


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