Macro for deleting every second Row of Data

G

Guest

hello
i am trying to use this macro for delete from my data every second ROW , but
couldn't use there is some error plz help me.
thanks in advance.

Sub abc()
Dim frow As Long, lrow As Long
Dim i As Long
frow = Selection.Row
lrow = Selection.Rows(Selection.Rows.Count).Row
For i = lrow To frow Step -2
Selection.Rows(A).Delete
Shift:=B:C
lShiftUp
Next

End Sub
 
K

Kaak

Sub abc()

Dim frow As Long, lrow As Long
Dim i As Long

frow = Selection.Row
lrow = Selection.Rows(Selection.Rows.Count).Row

For i = lrow To frow Step -2

Rows(i).Delete

Next

End Sub
 
N

Norman Jones

Hi Tufail,

It is not clear from your code anf question whether your intention is to:

- delete every second column A cell in the selection

or to

- delete every second row in the selection.

In the first case try:

'=============>>
Public Sub abc()
Dim frow As Long, lrow As Long
Dim i As Long

frow = Selection.Row
lrow = Selection.Rows(Selection.Rows.Count).Row
For i = lrow To frow Step -2
Cells(i, "A").Delete Shift:=xlShiftUp
Next
End Sub
'<<=============

in the second case, try instead:

'=============>>
Public Sub abc2()
Dim frow As Long, lrow As Long
Dim i As Long

frow = Selection.Row
lrow = Selection.Rows(Selection.Rows.Count).Row
For i = lrow To frow Step -2
Rows(i).Delete Shift:=xlShiftUp
Next
End Sub
'<<=============

If your intention is not met by eitherof these suggestions, perhaps you
could endeavour to restate your requirements.
 
B

Bob Phillips

Sub abc()
Dim frow As Long, lrow As Long
Dim i As Long
frow = Selection.Row
lrow = Selection.Rows(Selection.Rows.Count).Row
For i = lrow To frow Step -2
Rows(i).Delete
Next

End Sub


--
HTH

Bob Phillips

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top