PC Review


Reply
Thread Tools Rate Thread

Deleting every other row

 
 
=?Utf-8?B?bmlyMDIw?=
Guest
Posts: n/a
 
      15th Nov 2006
I am trying to write a macro that deletes every other row in spreadsheet, I
have written the following code

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 15/11/2006 by readn
'

'
Dim M As Range
Dim n As Integer

n = 9
Set M = Range("n.value:n.value")


For a = 1 To 150


M.Select
Selection.Delete Shift:=xlUp
n=n+2

Next a

End Sub

But I cannot get to work, any suggestions?
 
Reply With Quote
 
 
 
 
raymond.allan@bench.com
Guest
Posts: n/a
 
      15th Nov 2006
Try doing it in reverse

For a = 150 to 1 step -1

Raymond

nir020 wrote:
> I am trying to write a macro that deletes every other row in spreadsheet, I
> have written the following code
>
> Sub Macro1()
> '
> ' Macro1 Macro
> ' Macro recorded 15/11/2006 by readn
> '
>
> '
> Dim M As Range
> Dim n As Integer
>
> n = 9
> Set M = Range("n.value:n.value")
>
>
> For a = 1 To 150
>
>
> M.Select
> Selection.Delete Shift:=xlUp
> n=n+2
>
> Next a
>
> End Sub
>
> But I cannot get to work, any suggestions?


 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      15th Nov 2006

Sub Macro1()
Dim a As Long

Application.ScreenUpdating = False
For a = 150 To 2 Step -2
Rows(a).Delete
Next a
Application.ScreenUpdating = True

End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"nir020" <(E-Mail Removed)> wrote in message
news:5A71DE5E-3E32-450A-B22C-(E-Mail Removed)...
> I am trying to write a macro that deletes every other row in spreadsheet,

I
> have written the following code
>
> Sub Macro1()
> '
> ' Macro1 Macro
> ' Macro recorded 15/11/2006 by readn
> '
>
> '
> Dim M As Range
> Dim n As Integer
>
> n = 9
> Set M = Range("n.value:n.value")
>
>
> For a = 1 To 150
>
>
> M.Select
> Selection.Delete Shift:=xlUp
> n=n+2
>
> Next a
>
> End Sub
>
> But I cannot get to work, any suggestions?



 
Reply With Quote
 
=?Utf-8?B?RGF2ZSBSYW1hZ2U=?=
Guest
Posts: n/a
 
      15th Nov 2006
Bob's reply gives you the answer, put there are several problems with your
code for which you may find comments useful.

The first is the way you have attempted to set a range variable:
n = 9
Set M = Range("n.value:n.value")

Here, n is an integer varaible, but because you have included it in the
quotes, VBA cannot see it as a variable- just text. Also, you do not need the
..value. To use an integer variable to set a range object variable it is
better to use one of these:
Set M = Range("A" & n) 'uses & to concatenate text with the variable to
give "A9"
Set M = Cells(n,2) ' Row 9, column 2

Hope this helps,
Dave

"nir020" wrote:

> I am trying to write a macro that deletes every other row in spreadsheet, I
> have written the following code
>
> Sub Macro1()
> '
> ' Macro1 Macro
> ' Macro recorded 15/11/2006 by readn
> '
>
> '
> Dim M As Range
> Dim n As Integer
>
> n = 9
> Set M = Range("n.value:n.value")
>
>
> For a = 1 To 150
>
>
> M.Select
> Selection.Delete Shift:=xlUp
> n=n+2
>
> Next a
>
> End Sub
>
> But I cannot get to work, 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
Errors deleting email: Unknown error and very slow deleting messag Keith Rainey Microsoft Outlook Discussion 0 29th Apr 2010 03:53 AM
Deleting task without deleting e-mail; message views ideaman Microsoft Outlook Discussion 1 30th Sep 2009 03:34 AM
Deleting email in Outlook 2007 not deleting on Blackberry 8830 wir Jennifer L. Microsoft Outlook Discussion 0 17th Mar 2008 02:29 AM
Deleting Hyphens or Dashes from multiple cells without deleting the remaining content rmaloy Microsoft Excel Programming 5 9th Feb 2004 01:59 AM
Deleting or Manually Deleting Programs from the Add/Uninstall Program list Amy Bejm Windows XP Basics 3 21st Dec 2003 06:34 AM


Features
 

Advertising
 

Newsgroups
 


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