Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Deleting every other row

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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Deleting every other row

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?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Deleting every other row


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" wrote in message
...
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?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Deleting every other row

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
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
Deleting the text without deleting the formula gems04 Excel Worksheet Functions 3 January 30th 09 11:21 PM
Deleting cell data without deleting formula Tom Hall Excel Discussion (Misc queries) 4 October 29th 06 04:07 PM
deleting values in a worksheet without deleting the formulas patti Excel Worksheet Functions 1 October 28th 05 09:49 PM
how prevent formula in cell from deleting when deleting value???? sh-boom New Users to Excel 1 September 30th 05 06:12 PM
Deleting Hyphens or Dashes from multiple cells without deleting the remaining content rmaloy Excel Programming 5 February 9th 04 01:59 AM


All times are GMT +1. The time now is 08:25 AM.

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

About Us

"It's about Microsoft Excel"