ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Deleting every other row (https://www.excelbanter.com/excel-discussion-misc-queries/451506-re-deleting-every-other-row.html)

[email protected]

Deleting every other row
 
Alan Beban,

I tried to use your script, but when trying to save it, I receive the error-message:
Missing ; before statement. (line 3, file "Code")

Code:
function deleteEvenRows()
{
Set rng = Sheets("A1:A229").[a1]
For i = 1000 to 2 step -2
rng(i).EntireRow.Delete
Next
}

GS[_6_]

Deleting every other row
 
Alan Beban,

I tried to use your script, but when trying to save it, I receive the
error-message: Missing ; before statement. (line 3, file "Code")

Code:
function deleteEvenRows()
{
Set rng = Sheets("A1:A229").[a1]
For i = 1000 to 2 step -2
rng(i).EntireRow.Delete
Next
}


This is not VBA code.., it's .Net!


Function Delete_EvenRows()
Dim rng As Range, n&

Set rng = Sheets("Sheet1").Range("A1:A229")
'Add 1 for odd row count
For n = rng.Rows.Count + 1 to 2 step -2
Rows(n).Delete
Next
End Function

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus


GS[_6_]

Deleting every other row
 
It might be better to subtract 1 for odd row count if the row following
the range contains data you don't want to lose...

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus


GS[_6_]

Deleting every other row
 
Also, I forgot to ref the rng...

Function Delete_EvenRows()
Dim rng As Range, n&

Set rng = Sheets("Sheet1").Range("A1:A229")
'Adjust for odd row count
For n = rng.Rows.Count - Mod(rng.Rows.Count, 2) to 2 step -2
rng.Rows(n).Delete
Next
End Function

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus


Claus Busch

Deleting every other row
 
Hi,

another suggestion:

Sub DeleteRows()
Dim LRow As Long, i As Long

LRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = LRow To 2 Step -1
If i Mod 2 = 0 Then
'To delete odd rows
'If i mod 2 = 1 then
Rows(i).Delete
End If
Next
End Sub


Regards
Claus B.
--
Windows10
Office 2016

GS[_6_]

Deleting every other row
 
Correction...

Also, I forgot to ref the rng...

Function Delete_EvenRows()
Dim rng As Range, n&

Set rng = Sheets("Sheet1").Range("A1:A229")
'Adjust for odd row count

For n = rng.Rows.Count - (rng.Rows.Count Mod 2) to 2 step -2
rng.Rows(n).Delete
Next
End Function


--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus


Claus Busch

Deleting every other row
 
Hi,

Am Mon, 20 Jun 2016 18:52:58 +0200 schrieb Claus Busch:

Sub DeleteRows()
Dim LRow As Long, i As Long

LRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = LRow To 2 Step -1
If i Mod 2 = 0 Then
'To delete odd rows
'If i mod 2 = 1 then
Rows(i).Delete
End If
Next
End Sub


or define the row to start and try:

Sub Test()
Dim LRow As Long
Dim rngC As Range

Const rStart = 3 'First row to delete

LRow = Cells(Rows.Count, 1).End(xlUp).Row
For Each rngC In Range("A" & rStart & ":A" & LRow)
rngC.EntireRow.Delete
Next
End Sub


Regards
Claus B.
--
Windows10
Office 2016


All times are GMT +1. The time now is 04:25 PM.

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