Steve has attended:
Excel VBA Intro Intermediate course
Excel VBA
I trying to delete all rows based on the current region property starting in cell A12. The number of rows is not fixed and will vary each time. I have written the following code:
Dim WorkRange As Range
Dim Row As Range
Dim i As Variant
Sheets("Summary P&L Report").Activate
Set WorkRange = Sheets("Summary P&L Report").Range("A12").CurrentRegion
For i = WorkRange.Rows.Count To 1 Step -1
Set Row = WorkRange.Rows(i)
If Sheets("Summary P&L Report").Range ("A12").Cells.Value = "A" Then
Row.Delete
End If
Next i
Is the above the most efficient way to delete. Secondly I don't really want it to be conditional on range A12. I just want all rows (no matter how many there are) from A12 down to be deleted.
Many thanks
Steve
RE: Excel VBA
Hello Steve,
Not sure what you really need, but another way of deleting a selection is as follows:
Range("A12").CurrentRegion.Select
Selection.Delete
this will select the whole region and delete, this will save on the looping and deleting one row at a time! Maybe that is what you need?
I hope this resolves your question. If it has, please mark this question as resolved.
If you require further assistance, please reply to this post. Or perhaps you have another Microsoft Office question?
Have a great day.
Regards,
Mark
Microsoft Office Specialist Trainer