delete row macro in xlXP

  • Thread starter Thread starter d. williams
  • Start date Start date
D

d. williams

Hello. I'm attempting an Excel macro in Excel XP (running XP Pro) and
could really use some help.

I have a worksheet with several thousand rows. What I would like is to
write a macro which goes down A[1:n] and if An = An-1, I would like to
delete row n. So if A1="1183" and A2="1183", it deletes row 2.

I've written some relatively complex Word macros and some *very* simple
Excel macros; so I'm not totally unfamiliar, but I'm a clear newbie with
Excel's VBA. If anyone would be able to help me or refer me to a good
tutorial (I've been browsing the MVP's, but haven't been terribly
successful), I'd be extremely grateful.

Thank you. Danny.
 
Sub test()
Application.ScreenUpdating = False
With ActiveSheet
..Columns("A:A").Insert Shift:=xlToRight
..Range(.Range("B2"), _
..Range("B" & Rows.Count).End(xlUp)).Offset(0, -1).FormulaR1C1 = _
"=IF(RC[1]=R[-1]C[1],2/0,0)"
..Range("A" & Rows.Count).End(xlUp).Offset(1, 0).FormulaR1C1 = "=2/0"
..Range(.Range("A2"), _
..Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeFormulas,
16).EntireRow.Delete
..Columns("A:A").Delete Shift:=xlToLeft
End With
Application.ScreenUpdating = True
End Sub


--
XL2002
Regards

William

(e-mail address removed)

| Hello. I'm attempting an Excel macro in Excel XP (running XP Pro) and
| could really use some help.
|
| I have a worksheet with several thousand rows. What I would like is to
| write a macro which goes down A[1:n] and if An = An-1, I would like to
| delete row n. So if A1="1183" and A2="1183", it deletes row 2.
|
| I've written some relatively complex Word macros and some *very* simple
| Excel macros; so I'm not totally unfamiliar, but I'm a clear newbie with
| Excel's VBA. If anyone would be able to help me or refer me to a good
| tutorial (I've been browsing the MVP's, but haven't been terribly
| successful), I'd be extremely grateful.
|
| Thank you. Danny.
 
Glad to help.

--
XL2002
Regards

William

(e-mail address removed)

| > Sub test()
| > *snip*
| > End Sub
|
| Thank you tremendously! D.
 

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

Back
Top