Delete Rows based on # of rows (no variable?)

D

DanaK

SO frustrated. I'm a very light-weight VBA user. I have a document where I
need to delete several rows at a time, shifting up. Always three rows. I
tried recording this, but it doesn't work that way. I've dug around in Help
until I'm utterly confused as to where to start. I have a workbook with the
steps (what I was given to follow) but I only really need to know about
deleting rows. I think I might be able to figure out the rest. I'll need to
run this same sequence of steps multiple times, but I can figure that out as
well. Thanks to anyone who can help!--
DanaK
 
D

dmoney

This should give u what u need.


Sub tst()
Dim a As String
Dim b As String
Dim c As Integer
Dim d As String
c = 2
Range("a1").Select
Do Until ActiveCell.Value = "done"
If ActiveCell.Value = "x" Then
a = ActiveCell.Address
b = ActiveCell.Offset(c, 0).Address
d = a & ":" & b
Range(d).Select
Selection.EntireRow.Delete
End If
ActiveCell.Offset(1, 0).Activate
Loop
End Sub
 
D

DanaK

Thanks! I do have a question. Do I need to modify something? When I start it,
it runs all the way to the bottom & then I get an Application Defined or
Object error at line ActiveCell.Offset(1, 0).Activate. First row to delete
will be 8 & the last would be 24.
 
D

dmoney

I set the loop to end when the activecell is equal to "done" -- you can
either type the word done in column A at the bottom of your spreadsheet or
change the word done in the do statement to something that works for u.
 
D

DanaK

I typed done to end the sheet & that stopped it from running to the bottom,
but it doesn't delete any rows. It just drops down to the cell with done. Is
there something else I'm not doing?
DanaK
 
D

dmoney

look in the code -- there is a line that defines what it is looking for to
delete. in this case, i put in an x -- you can change that to meet what you
need.
 
D

dmoney

DanaK - Feel free to email me at [email protected] and attach your file
and I will see if I can better understand what you are trying to accomplish.
I am sure that we can get it done.

regards,
dmoney
 
D

DanaK

Sorry for the delay- had an out of town trip. I think I got it. It appears to
be doing what I needed it to. I really appreciate you being so patient! I
felt like 5 year old, what now? Why this? Hopefully more of this stuff will
sink in....Thank you!
 
Top